带标签的for循环,可用于break/continue跳出指定for循环
test:for(int i = 1; i < 5; i++) {
for(int j = 1; j < 5; j++) {
if (j % 2 == 0) {
break test; // 默认是跳出内层for循环。这里指定让它跳出外层for循环
// continue test; // 默认是跳出内层本次for循环,这里指定让它跳出外层本次for循环
}
System.out.print(i + "-" + j);
}
System.out.println();
}
break打印结果:1-1
continue打印结果:1-12-13-14-1