Recall & Review
beginner
What is a
for loop used for in JavaScript?A
for loop is used to repeat a block of code a specific number of times. It helps automate repetitive tasks.Click to reveal answer
beginner
Identify the three main parts inside the parentheses of a
for loop: for (___; ___; ___)The three parts are: 1) Initialization (sets a starting point), 2) Condition (checks if the loop should continue), 3) Update (changes the loop variable each time).
Click to reveal answer
beginner
What will this loop print?<br><pre>for (let i = 0; i < 3; i++) { console.log(i); }</pre>It will print:<br>0<br>1<br>2<br>Because it starts at 0 and runs while i is less than 3, increasing i by 1 each time.
Click to reveal answer
intermediate
How can you stop a
for loop early?You can use the
break statement inside the loop to stop it immediately when a condition is met.Click to reveal answer
intermediate
What happens if the condition in a
for loop is always true?The loop will run forever, causing an infinite loop, which can freeze or crash your program.
Click to reveal answer
Which part of the
for loop controls how many times the loop runs?✗ Incorrect
The condition is checked before each loop run to decide if the loop should continue.
What does this loop do?<br>
for (let i = 5; i > 0; i--) { console.log(i); }✗ Incorrect
It starts at 5 and decreases i by 1 each time until i is no longer greater than 0.
What keyword stops a
for loop immediately?✗ Incorrect
break exits the loop immediately.What will happen if you forget to update the loop variable in a
for loop?✗ Incorrect
Without updating, the condition may never become false, causing an infinite loop.
Which of these is a valid
for loop header?✗ Incorrect
Option A has the correct syntax with initialization, condition, and update inside parentheses.
Explain the three parts of a
for loop and how they work together.Think about how the loop starts, checks if it should continue, and changes each time.
You got /4 concepts.
Describe a real-life situation where a
for loop could help automate a task.Imagine doing something many times, like counting items or sending messages.
You got /4 concepts.