fork download
  1. class Program {
  2. public static void main(String... args) throws Exception {
  3. // 通常の使い方
  4. label1:
  5. while (true) {
  6. while (true) {
  7. break label1;
  8. }
  9. }
  10.  
  11. // ループじゃなくても名前付きbreak
  12. label2: {
  13. break label2;
  14. }
  15.  
  16. // ループじゃないと名前無しでbreakできない
  17. label3: {
  18. // break; // compile error
  19. }
  20.  
  21. // ループじゃないと名前無しでbreakできない
  22. {
  23. // break; // compile error
  24. }
  25.  
  26. while (true) {
  27. label4: {
  28. break; // 名前無しのbreakは常にループの内側を抜ける
  29. }
  30. System.out.printf("never executed\n");
  31. }
  32. }
  33. }
  34.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:30: error: unreachable statement
			System.out.printf("never executed\n");	
			^
1 error
stdout
Standard output is empty