The break and continue both are used to skip the iteration of a loop. These keywords are helpful in controlling the flow of the program.
Difference between break and continue:
- The break statement terminates the whole iteration of a loop whereas continue skips the current iteration.
- The break statement terminates the whole loop early whereas the continue brings the next iteration early.
- In a loop for switch, break acts as terminator for case only whereas continue 2 acts as terminator for case and skips the current iteration of loop.
Program 1: This program illustrates the continue statement inside a loop.
Program 2: This program illustrates the break statement inside a loop.
Program 3: Using switch inside a loop and continue 2 inside case of switch.
- What is the difference between “word-break: break-all” versus “word-wrap: break-word” in CSS ?
- Difference between continue and break statements in C++
- What is the use of number after “break” or “continue” statements in PHP ?
- continue command in Linux with examples
- PHP break (Single and Nested Loops)
- How to break an outer loop with PHP ?
- Break and Next statements in R
- CSS page-break-before Property
- CSS | box decoration break Property
- CSS | word-break Property
- How to break line without using <br> tag in HTML / CSS ?
- Tips for restarting career after a break
- break command in Linux with examples
- CSS | page-break-after Property
- CSS | page-break-inside Property
- How to insert line break before an element using CSS?
- How to prevent column break within an element?
- How to break _.each() function in Underscore.js ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.