Labelled breaks breaks out of several levels of nested loops inside a pair of curly braces. : Break Statement « Statement Control « Java Tutorial






public class Main {
  public static void main(String args[]) {

    int len = 100;
    int key = 50;
    int k = 0;
    out: {
      for (int i = 0; i < len; i++) {
        for (int j = 0; j < len; j++) {
          if (i == key) {
            break out;
          }
          k += 1;
        }
      }
    }
    System.out.println(k);
  }
}








4.8.Break Statement
4.8.1.The break Statement
4.8.2.Using the break Statement in a Loop: break out from a loop
4.8.3.Breaking Indefinite Loops
4.8.4.Labelled breaks breaks out of several levels of nested loops inside a pair of curly braces.
4.8.5.The Labeled break Statement