一道简单 的循环

题目:输出打印结果

public class Test1 {
    public static void main(String[] args) {
        int i = 100;
        while (true) {
            if (i++ > 100) {
                break;
            }
            System.out.println(i + "……1");
        }
        System.out.println(i + "……2");
    }
}

out:

101……1
102……2

分析:

  1. 第一次循环,i++的结果为100,if不成立,跳转至第八行,此时i为101,打印输出
  2. 往复第二次,I++为101,跳出整个循环,此时i为102

总结疏忽:

  1. 查看代码不仔细
  2. 执行循环体,一句句搞清楚

猜你喜欢

转载自www.cnblogs.com/zx-coder/p/12789960.html