本文共 673 字,大约阅读时间需要 2 分钟。
break:
for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (j == 1) { break; } System.out.println("i,j:" + i + "," + j); }}
输出:
i,j:0,0i,j:1,0i,j:2,0
continue:
for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (j == 1) { continue; } System.out.println("i,j:" + i + "," + j); }}
输出:
i,j:0,0i,j:0,2i,j:1,0i,j:1,2i,j:2,0i,j:2,2
跳出外层循环,添加标签:
outer:for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (j == 1) { break outer; } System.out.println("i,j:" + i + "," + j); }}
输出:
i,j:0,0
转载地址:http://qcytx.baihongyu.com/