break statement in java

Let’s learn break statement in java.

break statement in java

If java break is encountered in a loop, that loop will terminate and the control will shift to next statement of the same loop.

break and continue in java are the two important concepts.

Syntax:

break;

break statement is used to terminate case in switch case statement in java.

break java is also used in all types of loops such as while loop, do-while loop and for loop.

Let’s see an example on java break.

public class BreakStatementExample
{
   public static void main(String[] args) 
   {
      for(int a = 1; a <= 10; a++)
      {
         if(a == 3)
         {  
            // breaking loop  
            break;  
         }  
         System.out.println(a);  
      }
   }
}


Output:

1
2