For what value of i does while (i == i + 1) {} loop forever?
up vote
55
down vote
favorite
9
I ran cross this puzzler from an advanced programming course at a UK university exam. Consider the following loop, in which i is, so far, undeclared: while (i == i + 1) {} Find the definition of i , that precedes this loop, such that the while loop continues for ever. The next question, which asked the same question for this code snippet: while (i != i) {} was obvious to me. Of course in this other situation it is NaN but I am really stuck on the prior one. Does this have to do with overflow? What would cause such a loop to loop for ever in Java?
java loops types
share | improve this question
edited 2 days ago
...