for无限循环的几个情况
①判断条件为true,会无限循环
②省略了判断条件,会无限循环
---------------------------------------------------------------------------------------------------------------------------
①判断条件为true,会无限循环
package test010;
public class Main {
public static void main(String[] args) {
for (int i = 0; true; i++) {
System.out.println(i);
}
}
}
---------------------------------------------------------------------------------------------------------------------------
②省略了判断条件,会无限循环
package test010;
public class Main {
public static void main(String[] args) {
for (int i = 0;; i++) {
System.out.println(i);
}
}
}
package test010;
public class Main {
public static void main(String[] args) {
for (int i = 0; i < 5;) {
System.out.println(i);
}
}
}