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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.