Java break statement

Break Statement in Java Programming Language :

  1. Break statement in Java Programming is used to come out of the loop control statements.
  2. Break Statement is used to break : for Loop | while Loop | do-while loop
  3. Break Statements skips remaining statements and execute immediate statement after loop.
  4. Break statement is used whenever our condition is satisfied inside loop and we have to come outside the loop.
  5. Break statement is used to make looping statements more flexible and provides more power to it.

Syntax : Break Statement In Java Programming Language

break;

Different Ways of Using Break Statement in Java :

1.Break Statement used in For Loop

  • break statement will take control out of the loop.
  • All the statements will gets executed i.e statement 1 , statement 2 …. when it encounters break statement it will break loop and take control outside the loop.

break statement in java programming language

  • In the above diagram break statement will take control outside the loop . i.e, it will execute OutsideStatement1 next to break.

2.Break Statement used in While Loop

  • In this example we have written break statement inside while loop.
  • Whenever this statement executes then break will move control outside the while loop.

3.Break Statement used in While Loop

  • In do while it executes similarly as that of for and while loop.
  • break statement terminates do while loop.

4.Break Statement can also be used in Switch Case

Switch Case in Java