LESSON 15
For Loops
Learning objective: Repeat a known number of times with a for loop.
Understand
A for loop bundles setup, condition, and update in one line.
The for loop is ideal when you know how many times to repeat, such as iterating over an array by index. Its three parts — initializer, condition, and update — keep loop logic tidy.
Analogy: A for loop is like a metronome set to tick a fixed number of times.
See It in Action
Looping over items by index:
const items = ["a", "b", "c"];
for (let i = 0; i < items.length; i++) {
console.log(items[i]);
}How it works:
i runs from 0 up to the last index, and items[i] accesses each element in turn.Try It Yourself
- Loop over an array with a for loop.
- Log each element by index.
- Change the array and rerun.
Quick Quiz
What are the three parts of a for loop header?
Challenge
Use a for loop to print each item of an array.
Success condition: Your loop prints every array item in order.
+10 XP
Lesson Complete
You answered correctly and completed the required practice. Your progress has been saved on this device.
Continue to next lesson →