Break Statement
- The break statement is used to break the loop or switch case statements execution and brings the control to the next block of code after that particular loop or switch case it was used in.
- Break statements are used to bring the program control out of the loop it was encountered in.
- The break statement is used inside loops or switch statements in C Language.
One such example to demonstrate how a break statement works is,
Output
Here, when i became 6, the break statement got executed and the program came out of the while loop.
Continue Statement
- The continue statement is used inside loops in C Language. When a continue statement is encountered inside the loop, the control jumps to the beginning of the loop for the next iteration, skipping the execution of statements inside the body of the loop after the continue statement.
- It is used to bring the control to the next iteration of the loop.
- Typically, the continue statement skips some code inside the loop and lets the program move on to the next iteration.
- It is mainly used for a condition so that we can skip some lines of code for a particular condition.
- It forces the next iteration to follow in the loop unlike a break statement, which terminates the loop itself the moment it is encountered.
One such example to demonstrate how a continue statement works is
Output
Here, the continue statement was continuously executed while I remained less than 5. For all the other values of i, we got the print statement working.