结束循环

break:

意义:结束离其最近的循环

实例:

public class Test {
    public static void main(String[] args) {
        for (int j = 1; j <= 9; j++){
            for (int i = 1; i <= j; i++) {
                if (i==7){
                    break;
                }
                System.out.print(j +"*" +i +"=" +(j*i) +"\t");
            }
            System.out.println();
        }
    }
}
结果:

continue:

意义:结束当次循环

实例:

 

public class Test {
    public static void main(String[] args) {
        for (int j = 1; j <= 9; j++){
            for (int i = 1; i <= j; i++) {
                if (i==7){
                    continue;
                }
                System.out.print(j +"*" +i +"=" +(j*i) +"\t");
            }
            System.out.println();
        }
    }
}
结果:

 

posted @ 2021-10-03 23:28  隔岸稻花香  阅读(70)  评论(0编辑  收藏  举报