Java - Block statement with Label

Introduction

A labeled statement can be used with any type of a block statement.

The following code shows how to use a labeled break Statements:

Demo

public class Main {
  public static void main(String[] args) {
    blockLabel: {/*from   ww w. j av  a2  s . c om*/
      int i = 10;
      if (i == 5) {
        break blockLabel; // Exits the block
      }

      if (i == 10) {
        System.out.println("i is not five");
      }
    }

  }
}

Result

Related Topic