+ 1

Why is this an infinite loop?

int x = 0; while(x<5){ x++; x %= 4; }

27th Sep 2019, 5:10 PM
Juan Debenedetti
Juan Debenedetti - avatar
1 Antwort
+ 4
Because x will never be greater or equal to 5 while (x<5) //x=0 x++ // x=1 x%=4 // x=1%4, x=1 while (x<5) //x=1 x++ // x=2 x%=4 // x=2%4, x=2 while (x<5) //x=2 x++ // x=3 x%=4 // x=3%4, x=3 while (x<5) //x=3 x++ // x=4 x%=4 // x=4%4, x=0 while (x<5) //x=0 x++ // x=1 x%=4 // x=1%4, x=1 ....
27th Sep 2019, 5:21 PM
voja
voja - avatar