死循环

死循环

格式:
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;//关键字:用于终止循环
        }
    }
}

 

posted @ 2019-06-21 20:04  国民老公骚颖  阅读(319)  评论(0编辑  收藏  举报