Skip to content
dreamcode
dreamcode
Map
Break & continue
Lesson 14 of 48
+15 XP on finish
JS LOOPSChapter 3 · JS Collections & Loops

Break and Continue

Inside any loop, continue skips the rest of the current pass and moves on to the next one, and break leaves the loop completely. They keep loops simple: skip what you do not care about, and stop as soon as you have your answer.

Worked example

How it reads

  • continue skips even numbers without stopping the loop
  • break ends the loop entirely once n passes 7
  • Both work in for, for...of and while loops
Cloud tip: Searching for the first match? break as soon as you find it and skip the rest of the work.
index.js
JAVASCRIPT
real JavaScript, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Skip negative readings with continue, and stop the loop with break as soon as a reading is above 10. The output should be exactly 4, 7, 9.

Press Run to check your work.