【发布时间】:2011-04-14 16:53:23
【问题描述】:
这让我大吃一惊。以下测试失败;循环结束时 i 的值为 9,而不是 8。你能解释一下吗?
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);
}
}
【问题讨论】:
-
我个人会避免任何可能使运算符优先级混淆的代码...
标签: java while-loop