for(초기식; 조건식; 증감식)
{
____ 실행할 내용;
}

for(int i = 0; i <= 5; i++)
{
Console.WriteLine(i);
}
출력값: 0 1 2 3 4 5
for(int i = 5; i < 10; i--)
{
Console.WriteLine(i);
}
출력값: 조건식이 계속 참이어서 무한루프에 빠짐
int Count = 1;
while (Count <= 5)
{
Console.WriteLine(Count); // 1 2 3 4 5
Count++;
}
#include <stdio.h>
int main() {
int i = 0;
do {
printf("%d ", i);
i++;
} while (i < 5);
return 0;
}
for(int i = 1; i <= 10; i++)
{
if(i % 3 == 0)
{
continue;
}
Console.Write(i + " ");
}
출력값: 1 2 4 5 7 8 10
for(int i = 0; i < 3; i++)
{
Console.WriteLine("i의 값은: ");
for(int j = 0; j < 3; j++)
{
Console.Write(j+ " "); // 0 1 2
}
Console.WriteLine();
}
출력값:
for(int i = 1; i <= 9; i++)
{
for(int j = 1; j <= 9; j++)
{
Console.WriteLine(i + "X" + j + "=" + i * j);
}
Console.WriteLine();
}
for(int i = 0; i < 5; i++)
{
for(int j = 0; j <= i; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
출력값:
for(int i = 1;i <= 5;i++)
{
for(int j = i; j <= 5;j++)
{
Console.Write("*");
}
Console.WriteLine();
}
출력값:
ex) text라는 덩어리에서 하나씩 확인
string text = "qwer";
foreach(char c in text)
{
print(c);
}
string text = "qwer";
for(char & c : text)
{
cout << c << endl;
}