LESSON 13

Loops

Learning objective: Understand why loops repeat work efficiently.

Understand

Loops repeat a block of code many times.

Loops save you from writing the same code over and over. Every loop needs a starting point, a condition to keep going, and a way to move forward — otherwise it never stops.

Analogy: A loop is like doing push-ups: repeat the same action until you reach your count.

See It in Action

The idea of repetition:

// print 1, 2, 3 without repeating code
for (let i = 1; i <= 3; i++) {
  console.log(i);
}
How it works: The loop starts at 1, continues while i <= 3, and increases i each time — printing 1, 2, then 3.

Try It Yourself

  1. Write a loop that logs numbers 1 to 5.
  2. Change the range to 1 to 10.
  3. Add a stop condition and confirm it ends.

Quick Quiz

What does every loop need to avoid running forever?

Challenge

Log the numbers 1 through 5 using a loop.

Success condition: Your loop prints the sequence and then stops.