+ 2

I can't understand this code. Why it becomes infinite, and why outputs 0,1,2,3?

https://code.sololearn.com/c3UnfyK5F2wF/?ref=app

11th Dec 2017, 5:51 PM
Sadiqov Lətif
2 ответов
+ 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
11th Dec 2017, 6:02 PM
Frost
Frost - avatar
+ 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
11th Dec 2017, 6:07 PM
Veera Mani
Veera Mani - avatar