Break and Continue Statements


The break and continue statements are used to control how loops run in JavaScript.

Sometimes you want to stop a loop completely when a condition is met. Other times, you want to skip the current step and continue with the next one. The break and continue statements help you do exactly that.

These statements make your loops more flexible and powerful.

Difference Between break and continue

  • break     – stops the loop immediately  
  • continue  – skips the current iteration and moves to the next one  

Both are used to control the flow of loops in special situations.

In this example, the loop stops when the value of i becomes 5. The break statement immediately ends the loop.

This is useful when you find what you are looking for and do not need to continue looping.

Here, when i equals 3, the continue statement skips that iteration and moves to the next one.

The number 3 is not printed, but the loop continues with the remaining values.

This example shows how continue is used to skip invalid data while processing a list.

By using break and continue correctly, students can write smarter loops that handle special cases and real-world logic efficiently.