注:break和continue一般都是要结合循环使用的(for/while/do-while)
break
终止当前或指定循环
for(int i=0;i<10;i++){
if(i==3){
break;
}
System.out.println("i = "+i);
}
输出结果:
i = 0
i = 1
i = 2
continue
跳过本次循环,执行下一次循环
for(int i=0;i<10;i++){
if(i==3){
continue;
}
System.out.println("i = "+i);
}
输出结果:
i = 0
i = 1
i = 2
i = 4
i = 5
i = 6
i = 7
i = 8
i = 9
java学习笔记27--break和continue
最新推荐文章于 2024-11-14 14:48:14 发布