具名代码块
约 88 字小于 1 分钟
2025-07-22
在使用 break
或 contine
的时候可以指定停止那一段的代码块
class Main {
public static void main(String[] args) {
outer:
{
for (int i = 0; i < 10; i++) {
System.out.println("i = " + i);
if (i == 5) {
break outer;
}
}
System.out.println("This will not be printed because we broke out of the outer block.");
}
System.out.println("Exited the outer block.");
}
}