I am trying to understand why this cycle ends ...
@Test public void test() { int counter=0; int from = 0; int until = Integer.MAX_VALUE; while(counter <= until) { counter++; if(counter < from) { System.out.println("continuing " + counter + " <= " + from); continue; } } System.out.println("finished " + counter); }
while(counter <= until) should always be true , because the counter cannot be incremented beyond Integer.MAX_VALUE. Thus, the cycle should not end.
However, in Eclipse, if I run with a JUnit runner, I get:
finished 108772
If I run in the debugger, I get:
finished 125156
The output in if(counter < from) never output. If I delete this block, the code will still exit, this time in Integer.MAX_VALUE.
finished 2147483647
source share