while loop

what will happen to this code?
is it this code will become infinite loop?

int i=2;
while ( i<6);
{
cout << "some even : " << i << i+2 << i+4 << endl;
++i;
}
while (i <6);
're executing an empty while i <6 (always)
delete the semicolon.
1
2
3
4
5
    int i=2;
    while ( i<6) {
      cout << "some even : " << i << i+2 << i+4 << endl;
      ++i;
    } 
The code will loop for 4 times:

1
2
3
4
5
6
int i=2;
while ( i<6)
{
     cout << "some even : " << i << i+2 << i+4 << endl;
     ++i;
}
some even: 2 4 6
some even: 3 5 7
some even: 4 6 8
some even: 5 7 9


If you want it to print only even numbers, you have to change the code.

~ Raul ~
Last edited on
oh ic, thank you, to both of you! ^^
Topic archived. No new replies allowed.