Mega Code Archive

 
Categories / Java Tutorial / Statement Control
 

Label a statement block

A statement and a statement block can be labeled. 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.