java while 循环详解
while 循环用于重复执行一段代码,直到指定的条件变为假。 如果事先不知道循环次数,while 循环是理想的选择。与 for 循环不同,while 循环的初始化和迭代条件的更新不在循环结构内进行。
while 循环在循环体执行前检查条件,因此也被称为前测试循环(入口控制循环)。如果条件为真,则执行循环体;否则,跳过循环体,执行后续代码。
示例:打印前十个偶数
public class Calculation { public static void main(String[] args) { int i = 0; System.out.println("Printing the list of first 10 even numbers \n"); while (i < 10) { System.out.println(i * 2); i++; } } }
输出:
Printing the list of first 10 even numbers 0 2 4 6 8 10 12 14 16 18
以上就是循环的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号