死循环

死循环

格式:
for(;;){
}

while(true){
}

do{
}while(true)

如何终止死循环:
  1.将循环条件变为false
  2.通过使用break关键字终止循环

public class DeadLoopTest{

    public static void main(String[] args){
        /*
        for(;;){
            System.out.println("嘿嘿 哈哈 么么哒");
        }
        */

        /*
        boolean boo = true;
        while(boo){
            System.out.println("亲亲 抱抱 举高高");
            boo = false;
        }
        */

        while(true){
            System.out.println("亲亲 抱抱 举高高");
            break;//关键字:用于终止循环
        }
    }
}
原文地址:https://www.cnblogs.com/zmy-520131499/p/11066570.html