Break and Continue Statement
1.Break Statement:
The break statement is used when we want to break the cycle of execution after satisfying the condition. This statement break the further operation of loop, stop the execution and comes out of the process.
When this statement gets executed computer stop the execution of loop and goes outside the loop to the next statement. If break statement is within a nested loop then it exit from single loop only.
The break statement is used with while, do-while and for loop.
Ex:
2.Continue Statement:
The continue statement is used when execution of further statement in the loop is to be skipped. This statement bypass the execution of next statement and transfer control to the start of the loop for further execution of loop.
When this statement gets executed the control of computer goes back to the top of loop without executing the remaining statements.
This statement should be used only within the loop.
Ex:
Comments
Post a Comment