注:一定要注意控制条件语句控制的那个变量的问题,不要弄丢了,否则就容易死循环。
* 两种最简单的死循环格式
* while(true){...}
* for(;;){...}
while:
public class Test {
public static void main(String[] args) {
while (true) {
System.out.println("hello world");
}
//System.out.println("hello world"); //添加这句会报错.
}
}
for:
public class Test {
public static void main(String[] args) {
for (; ; ) {
System.out.println("hello world");
}
}
}