分析三种循环中返回继续和跳出机制的区别与联系
发布时间
阅读量:
阅读量
**
三种循环控制结构分析
**
//1.break 结束当前循环(内循环)
public static void main(String[] args) {
for (int i = 0 ; i < 5 ; i++ ){
for (int j = 0; j < 3 ; j++ ){
if (j == 1){
break ;
}
System.out.println("i的值为:" + i + " j的值为:" + j);
}
}
}
结果:
i的值为:0 j的值为:0
i的值为:1 j的值为:0
i的值为:2 j的值为:0
i的值为:3 j的值为:0
i的值为:4 j的值为:0
//2.o:break (用 o: 标记外循环) 结束所有循环(内外循环)
public static void main(String[] args) {
o:for (int i = 0 ; i < 5 ; i++ ){
fo
全部评论 (0)
还没有任何评论哟~
