Break and Continue Statement

 

1.Break  Statement:

When we want to stop the flow of execution after the condition has been met, we utilise the break statement. This statement ends the process, stops the loop's continued operation, and exits it.

 

When this statement is executed, the computer halts the loop's execution and moves on to the subsequent statement. If a break statement is contained within a nested loop, it only exits from that loop.

The break statement is used with while, do-while and for loop.

 

Ex:



2.Continue Statement:

When a loop's next statement needs to be skipped, the continue statement is used. This statement transfers control to the loop's beginning so that the loop can continue without being interrupted by the next statement.

Without processing the subsequent statements, the computer returns to the top of the loop when this statement is executed.

Only use this sentence inside of the loop.

 

Ex:


Comments