0% found this document useful (0 votes)
27 views

C4learn - Java Break Statement

Break statements in Java are used to exit a loop or switch statement. There are different ways to use a break statement including: (1) In a for loop, a break statement will exit the loop and continue execution at the statement after the loop; (2) In a while loop, a break statement will similarly exit the loop; (3) A break statement in a do-while loop exits the loop; (4) A break statement can also be used to exit a switch statement and continue execution at the statement after the switch. The break statement skips any remaining statements in the loop/switch and transfers control to the statement following the loop.

Uploaded by

qabiswajit
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

C4learn - Java Break Statement

Break statements in Java are used to exit a loop or switch statement. There are different ways to use a break statement including: (1) In a for loop, a break statement will exit the loop and continue execution at the statement after the loop; (2) In a while loop, a break statement will similarly exit the loop; (3) A break statement in a do-while loop exits the loop; (4) A break statement can also be used to exit a switch statement and continue execution at the statement after the switch. The break statement skips any remaining statements in the loop/switch and transfers control to the statement following the loop.

Uploaded by

qabiswajit
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Table of content [hide]

1 Break Statement in Java Programming Language :


2 Syntax : Break Statement In Java Programming Language
3 Different Ways of Using Break Statement in Java :
3.1 1.Break Statement used in For Loop
3.2 2.Break Statement used in While Loop
3.3 3.Break Statement used in While Loop
3.4 4.Break Statement can also be used in Switch Case

o
o
o
o

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 | dowhile 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 encountersbreak 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.

4.Break Statement can also be used in Switch Case

You might also like