What is the equivalent while loop for the code below?

1
2
3
4
5
6
7
int count = 1;
for ( ; ; count++)
if (count < 3)
cout << count;
else
break;
12


this is what i got

1
2
3
4
While(int count = 1) 
 If (count < 3){ 
     Cout << count;}
     Count++; 
Close, but you've coded an infinite loop. Try this:

1
2
3
4
5
6
7
8
9
10
11
12

int count = 1;

while( count < 3 )
    {
    cout << count;

    count++;

    }    /*    while( count < 3 )    */

1
2
3
4
5
6
int count = 1;
for ( ; ; count++)
if (count < 3)
cout << count;
else
break;

I certainly do hope that you aren't serious.
The correct version of the above is this:

for (int i=1;i<3;i++)cout << i;
Athar, I think that johnhuge wanted his example written as a "while" loop.
I'm aware of that. You already answered his question, my problem is with his initial "example".
Topic archived. No new replies allowed.