什么是break
for (int i = 1; i < 10; i++) {if(i == 5){break;}System.out.println(i);
}
// 结果为 1 2 3 4
什么是continue
for (int i = 1; i < 10; i++) {if(i == 5){continue;}System.out.println(i);
}
// 结果为 1 2 3 4 6 7 8 9
关于goto关键字
String str = "";
outer:for (int i = 1; i <= 2; i++) {for (int j = 1; j <= 2; j++) {for (int k = 1; k <= 2; k++) {str += k;if (k == 2){continue outer;}}}
}
System.out.println(str);
// 结果为 1212