This startles me. The following test fails; the loop finishes with i having the value 9, not 8. Can you explain it?
import junit.framework.TestCase;
public class TestDoWhile extends TestCase {
final int LIMIT = 8;
public void testDoWhile() throws Exception {
int i = 0;
do {
} while (i++ < LIMIT);
assertEquals(LIMIT, i);
}
}
You need to do this:
the way you have it the condition is evaluated, and then i is incremented. If you do the above, i will be incremented before the evaluation.