java快速结束嵌套循环
java快速结束嵌套循环
快速结束for循环
out:for (int i = 0; i < 5; i++) {in:for (int j = 0; j < 5; j++) {if (j == 2) {break out;}System.out.println("i= " + i + " j= " + j);}}
解释 将外层for循环起别名 o u t \color{red}{out} out,将内层for循环起别名 i n \color{red}{in} in
b r e a k \color{red}{break} break o u t ; \color{red}{out;} out; 结束外层for循环。
运行结果:
学的不是技术,更是梦想!!!