理解for循环和条件

DMC*_*DMC 0 java for-loop

以下是我无法理解的代码.输出为13 15 x = 6.我理解我们如何获得数字13因为当我们经历循环时,x的值是5并且其对应的y值是12.因此,如果x> 4,则我们增加y,这给出了值为13.下一个打印的数字out然后应该是14因为x的下一个值是6并且它的相应y值是13所以当你增加它时它将是14.但是当我运行代码时它给出了不同的答案.有人可以帮忙吗?谢谢

public class Output {
  public static void main(String[] args) {
    Output o = new Output();
    o.go();
  }


  void go() {
    int y = 7;
    for (int x = 1; x < 8; x++) {
        y++;
        if (x > 4) {
            System.out.print(++y + " ");
        }
        if (y > 14) {
            System.out.println(" x = " + x);
            break;
        }
    }
  }
}  ? 
Run Code Online (Sandbox Code Playgroud)

小智 5

原因是因为++ y在打印之前递增y.

y ++会做你所期望的