把下面的例子copy到你的IDE中,运行一下,好好分析下结果。你就会深刻理解java中的标签用法了,与此同时,你还掌握了break和continue的用法,答案不贴出来了!
经典案例:
public static void main(String[] args) {
label: for (int i = 0; i < 4; i++) {for (int j = 1; j <= 10; j++) {
if (j % 4 == 0) {
break;
// continue;
// break label;
// continue label;
// 报编译异常
// System.out.println("王菲又怀孕了!");
}
System.out.print(j);
}
System.out.println();
}
}