loops

May 21, 2010 at 1:06am
Can anyone just explain to me why this loop produuces this outcome.

Outcome (bolded) j : 0 3 6 9 12
Outcome (bolded) i : 0 1 2 3 4

I never expected j to go beyond 10.why is like so.is j <= 10 ignored?
1
2
3
4
5
6
7
8

int i = 0, j = 0;
while ( j <= 10 )
{
j += 3;
i++;
}
cout << i ;
May 21, 2010 at 3:00am
The while loop will only terminate when j > 10, and the first time that occurs is when j == 12.
May 21, 2010 at 3:14am
thanks
Topic archived. No new replies allowed.