Java break statement
Contents
Break Statement in Java Programming Language :
- Break statement in Java Programming is used to come out of the loop control statements.
- Break Statement is used to break : for Loop | while Loop | do-while loop
- Break Statements skips remaining statements and execute immediate statement after loop.
- Break statement is used whenever our condition is satisfied inside loop and we have to come outside the loop.
- 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.
- 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.