Recall & Review
beginner
What is the main purpose of a loop in programming?
A loop repeats a block of code multiple times until a condition is met or no longer true.
Click to reveal answer
beginner
What are the three main parts of a
for loop in JavaScript?Initialization (start value), condition (when to stop), and update (how to change the value each time).
Click to reveal answer
intermediate
What happens if the loop condition is always true?
The loop runs forever, causing an infinite loop that can freeze or crash the program.
Click to reveal answer
intermediate
How does a
while loop differ from a do...while loop?A
while loop checks the condition before running the code, but do...while runs the code once before checking the condition.Click to reveal answer
beginner
What is the role of the
break statement inside a loop?It immediately stops the loop and exits it, even if the loop condition is still true.
Click to reveal answer
Which part of a
for loop runs only once at the start?✗ Incorrect
Initialization sets the starting point and runs once before the loop begins.
What will happen if the condition in a
while loop is false at the start?✗ Incorrect
A
while loop checks the condition first, so if false, it skips the loop body.What does the
continue statement do inside a loop?✗ Incorrect
continue skips the remaining code in the current loop cycle and jumps to the next iteration.In a
do...while loop, when is the condition checked?✗ Incorrect
The
do...while loop runs the code once, then checks the condition to decide if it repeats.What is the output of this code?<br>
for(let i = 0; i < 3; i++) {<br> if(i === 1) break;<br> console.log(i);<br>}✗ Incorrect
The loop stops when i equals 1, so only 0 is printed.
Explain how a
for loop executes step-by-step.Think about the order of the three parts and when the code inside runs.
You got /5 concepts.
Describe the difference between
while and do...while loops.Focus on when the condition is checked in each loop.
You got /4 concepts.