break and continue, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
break and continue in one minute
What students need to know
This exits the loop as soon as found becomes true. This skips the rest of the pass whenever x is even.
break stops the loop entirely, skipping any remaining passes. continue moves straight to the next pass without stopping the loop.
Mistakes students make
- 'break' is the keyword to exit a loop, not 'stop'.
- 'continue' is the keyword to skip a pass, not 'skip'.
- 'break' must be lowercase - a capital B causes an error.
- 'continue' must be lowercase - a capital C causes an error.
PREVIOUS · MODULE 20For Loops
YOU ARE HERE · MODULE 21break and continue
NEXT · MODULE 22Arrays – Creation and Indexing
What students will learn in this module
Every question in Module 21
Quick questions
- Does break exit a loop completely?ANoBYes
- Does continue skip the rest of the current pass only?AYesBNo
- Is 'stop' a valid keyword to exit a loop?ANoBYes
- Must 'break' be written in lowercase?ANoBYes
- Does continue stop the loop from running any more passes?ANoBYes
Key terms
Students type the meaning of:
break
Match the pairs
break;Match it to what it doescontinue;Match it to what it doesStops a loop early once a condition is metMatch it to what it doesSkips even numbers while loopingMatch it to what it doesif (i === 4) { stop; }Match it to what it doesif (i === 2) { skip; }Match it to what it doesFill in the blanks
if (i === 4) { _____; }Hint: Type the keyword that exits the loop completely.
if (i === 2) { ________; }Hint: Type the keyword that skips to the next pass of the loop.
if (n > 10) { _____; }Hint: Type the keyword that exits the loop completely.
if (x % 2 === 0) { ________; }Hint: Type the keyword that skips to the next pass of the loop.
if (found) { _____; }Hint: Type the keyword that exits the loop completely.
Spot the error
Question 1
Aif (i === 4) {Bstop;C}
Question 2
Aif (i === 2) {Bskip;C}
Question 3
ABreak;Bfor (let i = 0; i < 5; i++) {Cif (i === 3) {D}
Question 4
Afor (let j = 0; j < 5; j++) {Bif (j === 1) {C}DContinue;
Question 5
Afor (let k = 0; k < 5; k++) {Bif (k > 3) {Cconsole.log(k);D}Ebrek;
