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.
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.
continue statement: 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.
Tabular Difference Between the break and continue statement:
|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.|
Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.