![]() |
VOOZH | about |
In this article, we will discuss the difference between the break and continue statements in C. They are the same type of statements which is used to alter the flow of a program still they have some difference between them.
: This statement terminates the smallest enclosing loop (i.e., while, do-while, for loop, or switch statement). Below is the program to illustrate the same:
i = 0, j = 0 1 i = 1, j = 0 1 i = 2, j = 0 1 i = 3, j = 0 1 i = 4, j = 0 1
Explanation: In the above program the inner for loop always ends when the value of the variable j becomes 2.
: This statement skips the rest of the loop statement and starts the next iteration of the loop to take place. Below is the program to illustrate the same:
i = 0, j = 0 1 3 4 i = 1, j = 0 1 3 4 i = 2, j = 0 1 3 4 i = 3, j = 0 1 3 4 i = 4, j = 0 1 3 4
Explanation: In the above program the inner for loop always skip the iteration when the value of the variable j becomes 2.
:
| Break Statement | Continue Statement |
|---|---|
| The Break statement is used to exit from the loop constructs. | The continue statement is not used to exit from the loop constructs. |
| The break statement is usually used with the switch statement, and it can also use it within the while loop, do-while loop, or the for-loop. | The continue statement is not used with the switch statement, but it can be used within the while loop, do-while loop, or for-loop. |
| When a break statement is encountered then the control is exited from the loop construct immediately. | When the continue statement is encountered then the control automatically passed from the beginning of the loop statement. |
| Syntax: break; | Syntax: continue; |
| Break statements uses switch and label statements. | It does not use switch and label statements. |
| Leftover iterations are not executed after the break statement. | Leftover iterations can be executed even if the continue keyword appears in a loop. |