在while循环中更新语句

问题描述 投票:0回答:1

导入java.util.*;

导入java.io.*;

主类{

public static void main(String[] args) {

int a=0;

同时(a++<4) {

System.out.println("检查");

}

}

}

这里我们得到结果 查看 查看 查看 检查

但我有一个疑问是

   In the while loop there is no update statement to execute to loop repeatedly 

我认为答案只是 1 次“检查”。但是当我执行代码时,它显示 4 次“检查”。

我不是it学生。所以请给我解释清楚理解。

java loops while-loop
1个回答
0
投票

while 循环仅适用于条件(真/假)。und 必须像 while(a<4) and not like while(a++<4) your code must bei like this

 while(a<4) {
    System.out.println("Check");
    a++;
    }

语法 while 循环与 for 循环不同

for (int a=0;a<4;a++)

同时

 while(a<4) {
a++;
}
© www.soinside.com 2019 - 2024. All rights reserved.