--- title: "00-循环语句" created: 2025-12-02 tags: - 项目 aliases: - 循环语句 --- # 循环语句 ## while循环 与C++、Python类似,例如: ```java int i = 0; while (i < 5) { System.out.println(i); i ++ ; } ``` ## do while循环 与C++、Python类似,例如: ```java int i = 0; do { System.out.println(i); i ++ ; } while (i < 5); ``` do while语句与while语句非常相似。唯一的区别是,do while语句限制性循环体后检查条件。不管条件的值如何,我们都要至少执行一次循环。 ## for循环 与C++、Python类似,例如: ```java for (int i = 0; i < 5; i ++ ) { // 普通循环 System.out.println(i); } int[] a = {0, 1, 2, 3, 4}; for (int x: a) { // forEach循环 System.out.println(x); } ``` ## 练习题 [[01-偶数|偶数]] [[02-正数|正数]] [[05-递增序列|递增序列]] [[03-约数|约数]] [[04-菱形|菱形]] --- **项目分区导航**: [[05-零食|零食]] ⬅️ | 00-循环语句 | ➡️ [[01-偶数|偶数]]