continue和break关键字

break强制退出循环

continue终止某次循环,循环体内continue之后的语句不执行,接着执行下一次循环

break强制退出循环

continue终止某次循环,循环体内continue之后的语句不执行,接着执行下一次循环

package test.operator;

public class continueDemo01{
    public static void main(String[] args) {
        int i = 0;
        while (i<100){
            i++;
            //遇到整十数换行
            if(i%10 == 0){
                System.out.println(i);
                continue;
            }
            System.out.print(i+"\t");
        }
    }
}
package test.operator;

public class breakDemo01 {
    public static void main(String[] args) {
        int i = 0;
        while (i<100){
            i++;
            System.out.print(i+"\t");
            //打印30之前的数字
            if(i==30){
                break;
            }
        }
    }
}
posted @ 2023-03-17 18:52  chengh0618  阅读(10)  评论(0编辑  收藏  举报