Lesson 34

Break & Continue

Learn loop control statements

20 min
+25 XP
Step 1 of 5

The Break Statement

The break statement lets you exit a loop early, even if the loop condition is still true.

When to use break:

  • • When you've found what you're searching for
  • • When a certain condition is met
  • • To stop processing early to save time

Basic Example:

for (let i = 1; i <= 10; i++) {
  if (i === 6) {
    break // Stop the loop when i equals 6
  }
  console.log(i)
}
// Output: 1, 2, 3, 4, 5

Try the Break Statement!

Notice:

The loop stops completely when it hits break. Numbers 6-10 are never printed!