You are here: Home / Topics / Label block and break example in Java

Label block and break example in Java

Filed under: Java on 2023-08-18 06:44:16

//  Label block and break

public class BreakAsGoto{

   public static void main(String[] args) {

       aBlock:
       {
           bBlock:
           {
               cBock:
               {
                   System.out.println("Before using break");
                   if (true) {
                       break Bblock;
                   }
                   System.out.println("This will never execute");
               }
               System.out.println("This is never execute");
           }
           System.out.println("This will be executed");
       }
   }
}


Output:

Before using break
This will be executed

About Author:
Y
Yatendra Sir     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.