Recall & Review
beginner
What does the
break statement do in JavaScript loops?The
break statement immediately stops the loop and exits it, skipping any remaining iterations.Click to reveal answer
beginner
Can
break be used outside of loops in JavaScript?No,
break is used only inside loops (for, while, do-while) or switch statements to exit them early.Click to reveal answer
intermediate
What happens if you use
break inside a nested loop?The
break statement only exits the innermost loop where it is used, not all outer loops.Click to reveal answer
beginner
Example: What will this code output?<br><pre>for(let i = 0; i < 5; i++) {<br> if(i === 3) break;<br> console.log(i);<br>}</pre>It will print:<br>0<br>1<br>2<br>Because when
i becomes 3, the break stops the loop immediately.Click to reveal answer
beginner
How does
break differ from continue in loops?break stops the entire loop immediately.<br>continue skips only the current iteration and moves to the next one.Click to reveal answer
What does the
break statement do inside a loop?✗ Incorrect
break immediately stops the loop and exits it.Where can you use the
break statement in JavaScript?✗ Incorrect
break is valid inside loops and switch statements.What happens if
break is used inside nested loops?✗ Incorrect
break exits only the loop where it is used, usually the innermost one.What will this code print?<br>
for(let i=0; i<3; i++) { if(i===1) break; console.log(i); }✗ Incorrect
When i is 1,
break stops the loop, so only 0 is printed.How is
break different from continue?✗ Incorrect
break stops the loop; continue skips only the current iteration.Explain how the
break statement works inside a loop and give a simple example.Think about when you want to stop repeating something early.
You got /3 concepts.
Describe the difference between
break and continue in loops.One stops all, the other skips one.
You got /3 concepts.