while(布尔表达式){ // 循环内容 }
public class Demo01 { public static void main(String[] args) { int i = 0; while (i < 100){ i++; System.out.println(i); } } }
public class Demo02 { public static void main(String[] args) { int i = 0; int sum = 0; while (i <= 100){ sum = sum + i; i++; } System.out.println(sum); } }
do { // 循环内容 }while(布尔表达式)
public class Demo02 { public static void main(String[] args) { int i = 0; int sum = 0; do { sum = sum + i; i++; } while (i <= 100); System.out.println(sum); } }
for(初始化;布尔表达式;更新){ // 循环语句 }
public class Demo03 {
public static void main(String[] args) {
for (int i = 1;i <= 100;i++){
System.out.println(i);
}
}
}