+ 1
why does result is 5?
4 odpowiedzi
+ 2
First loop makes i=4
I=I+1=>i=1, and next i++; so I=2
I=I+1=>i=3, and next i++; so I=4
4<3 false, loop stops..
if block i%2==0 cause i++; so i=5 now
If provide your understandings then it helps you correct your answer, if any wrong..
Hope it helps..
+ 1
In the last iteration
i= 3 , then i++ = 4 according to (i =0, i<3, i++)
Then it moves to the conditions
if i%2 ==0 , which is true then it increment by 1
Making it 5
I hope this helps
+ 1
This is the order of execution :
i=0;
i<3
i=i+1
i++;
i < 3
i=i+1
i++;
i<3
..
..
there checks are
0<3 true initial
2<3 true, after 1st iteration
4<3 false, after 2nd iteration
0
But when i=3, this loop will stops.
I = 3, it's <3, so i =2