Consider this simple code:
// E1
public void doTest(String pattern) {
int counter = 0;
while (counter < 3) {
counter = counter++;
}
System.out.println("Done");
}
This causes an infinite loop.
However if the statement that increments the counter is written like this:
E2. counter = ++counter;
or this
E3. counter++;
It terminates normally. I understand that the incrementing occurs after the assignment in the version that fails which explains why E2 works, but I thought java assigned the results of an increment in the variable that is incremented as in E3. So I'm perplexed as to why E1 fails but E3 does not.