int count = 0; //counter선언
while ( count < 10 ) //while 조건이 true여야 출력된다.
{
cout << count << endl;
++count;
if( count == 10 ) break;
}
몇 번에 한번씩 어떤 행위를 하도록 출력하고 싶다.
int count = 1;
while( count < 100)
{
if( count%5 == 0 ) cout << "Hello" << count << endl;
count ++;
}
while문 안에 while문
int outer_count = 1;
while (outer_count <= 5)
{
int inner_count =1;
while(inner_count <= outer_count)
{
cout << inner_count++ << " ";
}
cout << endl;
++outer_count;
<Result>
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
'programming > c++' 카테고리의 다른 글
5.7 반복문 for (0) | 2019.05.04 |
---|---|
5.6 do while (0) | 2019.04.30 |
5.4 goto (0) | 2019.04.30 |
5.3 switch case (0) | 2019.04.30 |
5.1 제어 흐름 소개 (0) | 2019.04.30 |