+ 1
Why is this an infinite loop?
int x = 0; while(x<5){ x++; x %= 4; }
1 Answer
+ 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
....