/**
* 测试带标签的break
*/
public class Test {
public static void main(String[] args) {
outer: for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
if (j == 2) {
break outer;
}
System.out.println("i = " + i + " j = " + j);
}
}
}
}
执行结果:
i = 0 j = 0
i = 0 j = 1
/**
* 测试带标签的continue
*/
public class Test {
public static void main(String[] args) {
outer: for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
if (j == 2) {
continue outer;
}
System.out.println("i = " + i + " j = " + j);
}
}
}
}
i = 0 j = 0
i = 0 j = 1
i = 1 j = 0
i = 1 j = 1
i = 2 j = 0
i = 2 j = 1