Learn Without Walls
← Module 5 Home Lesson 2 of 4 Next Lesson →

Lesson 2: Why Loops Save Work

Estimated time: 15-20 minutes | Screen-Free Activity

What You Will Learn

By the end of this lesson, your child will be able to:

The Problem with Repeating Yourself

Imagine your parent asks you to set the table for dinner. There are four people in your family. You could write the instructions like this:

Setting the Table -- The Long Way

  1. Put a plate at seat 1
  2. Put a fork at seat 1
  3. Put a napkin at seat 1
  4. Put a plate at seat 2
  5. Put a fork at seat 2
  6. Put a napkin at seat 2
  7. Put a plate at seat 3
  8. Put a fork at seat 3
  9. Put a napkin at seat 3
  10. Put a plate at seat 4
  11. Put a fork at seat 4
  12. Put a napkin at seat 4

That is 12 instructions! And look -- the same three steps repeat four times. That is a lot of writing for something simple.

Now look at the same task written with a loop:

Setting the Table -- The Loop Way

Repeat 4 times:

  1. Put a plate at the next seat
  2. Put a fork at the next seat
  3. Put a napkin at the next seat

That is only 3 instructions inside a loop. Much shorter, much cleaner, and it does the exact same job!

Talk About It (Parent and Child)

Ask your child: "Which version would you rather write -- 12 steps or 3 steps with a repeat? Why?" This helps them feel the benefit of loops in their gut, not just their head.

The Lazy Programmer

In coding, there is a famous idea called the "lazy programmer." But it does not mean lazy in a bad way! It means a programmer who is smart enough to find shortcuts. A lazy programmer thinks:

The Lazy Programmer Rule: If you are writing the same thing more than once, there is probably a better way. Good coders look for patterns and use loops instead of repeating themselves.

Being a "lazy programmer" is actually a compliment! It means you are clever, efficient, and you do not waste time. The best coders in the world are "lazy" -- they find the shortest, smartest way to get things done.

Real-World Lazy Thinking

  • Instead of hand-writing 30 birthday invitations, you print them. (That is a loop: "repeat 30 times: print one invitation.")
  • Instead of telling each friend the party details one at a time, you send a group message. (One message, many people.)
  • Instead of washing each dish by hand, you load them all into the dishwasher. (Let the machine do the repeating!)

Rewriting with "Repeat"

Let us practice turning long, repeated instructions into short loop instructions. The trick is to find the part that repeats and figure out how many times it happens.

Without a Loop (10 steps)

Jump up.
Jump up.
Jump up.
Jump up.
Jump up.
Jump up.
Jump up.
Jump up.
Jump up.
Jump up.

With a Loop (1 step)

Repeat 10 times:
  Jump up.

Without a Loop (8 steps)

Step forward.
Step forward.
Step forward.
Step forward.
Turn right.
Step forward.
Step forward.
Step forward.
Step forward.
Turn right.

With a Loop (3 steps)

Repeat 2 times:
  Step forward.
  Step forward.
  Step forward.
  Step forward.
  Turn right.

See how much shorter the loop version is? And if you wanted to change "step forward" to "hop forward," you would only need to change it in one place instead of changing every single line. That saves work and prevents mistakes!

Loops Prevent Mistakes

There is another big reason loops are so useful: they help you avoid mistakes. When you write the same thing over and over, it is easy to accidentally skip a step or change something by accident.

Spot the Mistake

Can you find the error in these instructions?

  1. Put a sticker on page 1
  2. Put a sticker on page 2
  3. Put a sticker on page 3
  4. Put a sticker on page 4
  5. Put a sticker on page 5
  6. Put a sticker on page 7
  7. Put a sticker on page 8

Did you catch it? Page 6 is missing! When you write the same thing many times, it is easy to make a small error. With a loop -- "Repeat for pages 1 to 8: put a sticker on the page" -- you cannot skip a page.

Talk About It (Parent and Child)

Ask your child: "If you had to write 'clap your hands' 100 times on paper, do you think you would make any mistakes? What if you just wrote 'Repeat 100 times: clap your hands' instead?" This shows them why loops are not just shorter -- they are also safer.

Two Kinds of Loops

Not all loops are the same. There are two main kinds:

Count Loop: A loop that repeats a certain number of times. Example: "Repeat 5 times: jump." You know exactly how many times it will happen.

Until Loop: A loop that keeps going until something changes. Example: "Repeat until the song ends: keep dancing." You do not know how many times it will repeat -- it depends on when the song ends.

Examples of Each Kind

Count Loops:

  • Repeat 3 times: knock on the door
  • Repeat 10 times: do a jumping jack
  • Repeat 4 times: sing "Happy Birthday"

Until Loops:

  • Repeat until you find your shoes: look in the next room
  • Repeat until the jar is full: add one marble
  • Repeat until mom says stop: keep stirring the batter

Activity: Shrink the Instructions

Screen-Free Activity (10 minutes)

What you need: Paper and a pencil.

What to do: Rewrite each set of instructions using a loop. Write "Repeat ___ times:" and then the steps that go inside the loop.

Challenge 1:

  1. Clap your hands
  2. Clap your hands
  3. Clap your hands
  4. Clap your hands
  5. Clap your hands
  6. Clap your hands

Challenge 2:

  1. Draw a line
  2. Turn right
  3. Draw a line
  4. Turn right
  5. Draw a line
  6. Turn right
  7. Draw a line
  8. Turn right

Challenge 3:

  1. Water the first plant
  2. Move to the next plant
  3. Water the first plant
  4. Move to the next plant
  5. Water the first plant
  6. Move to the next plant
  7. Water the first plant
  8. Move to the next plant
  9. Water the first plant
  10. Move to the next plant

Answers: (1) Repeat 6 times: clap your hands. (2) Repeat 4 times: draw a line, turn right. (This makes a square!) (3) Repeat 5 times: water the plant, move to the next plant.

Check Your Understanding

1. Why do coders use loops instead of writing the same instruction many times?

Answer: Loops save work, make instructions shorter and cleaner, and help prevent mistakes. Instead of writing something 100 times, you write it once inside a loop.

2. What does "the lazy programmer" mean?

Answer: A "lazy programmer" is a smart programmer who finds the shortest, cleverest way to do things. They look for patterns and use loops instead of repeating themselves. It is a good thing!

3. What is the difference between a "count loop" and an "until loop"?

Answer: A count loop repeats a set number of times (like "repeat 5 times"). An until loop keeps repeating until something happens (like "repeat until the bowl is empty"). With a count loop, you know exactly how many times. With an until loop, it depends.

Key Takeaways

Ready for More?

Next Lesson

In Lesson 3, you will use loops to create repeating patterns in art and music. Get ready to clap, stamp, and draw!

Start Lesson 3

Module Progress

You have completed Lesson 2! Two more lessons to go in Module 5.