+ 2
I can't understand this code. Why it becomes infinite, and why outputs 0,1,2,3?
2 odpowiedzi
+ 12
x%=4 causes infinite loop...
when x++ becomes 4
x gets reset due to the above condition
i.e x= x%4 => x=4%4 which is 0
so the new value is now 0
again it increments as while condition is satisfied (0<5) and goes on
0 1 2 3 0 1 2 3 and so on
+ 1
actually 4%4 is 0, so that condition never false
1%4 = 1;
2%4=2;
3%4 = 3;
4%4=0;
and then x++ is increase one value