Label a statement block : Statement « Statement Control « Java Tutorial






  1. A statement and a statement block can be labeled.
  2. Label names follow the same rule as Java identifiers and are terminated with a colon.
public class MainClass {

  public static void main(String[] args) {
    int x = 0, y = 0;
    sectionA: x = y + 1;
  }

}

And, here is an example of labeling a block:

public class MainClass {

  public static void main(String[] args) {
    start: {
      // statements
    }
  }

}

Label statement can be referenced by the break and continue statements.









4.1.Statement
4.1.1.An Overview of Java Statements
4.1.2.Expressions
4.1.3.Declaring and defining multiple variables in a single statement
4.1.4.Label a statement block
4.1.5.Spreading a single declaration over several lines
4.1.6.How to write multiple assignments in a single statement
4.1.7.Combining both statements into one
4.1.8.Statement Blocks