10. while文制御
10. while文制御
while文
lesson 026
class Lesson026 { public static void main(String args[]) { int count = 0; while (count <= 10000) { System.out.print("count = " + count + "\r"); count++; } } }
実行結果
L:\>java Lesson026
count = 10000
無限ループ
lesson 027
class Lesson027 { public static void main(String args[]) { int count = 0; while (true) { System.out.print("count = " + count + "\r"); count++; if (count > 10000) break; } } }
実行結果
L:\>java Lesson027
count = 10000
do文
lesson 028
class Lesson028 { public static void main(String args[]) { int count = 10000; do { System.out.print("count = " + count + "\r"); count++; } while (count < 10000); } }
実行結果
L:\>java Lesson028
count = 10000