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:
- Explain why repeating the same instruction many times is inefficient
- Rewrite a list of repeated steps using "repeat" language
- Understand the idea of the "lazy programmer" (working smarter, not harder)
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
- Put a plate at seat 1
- Put a fork at seat 1
- Put a napkin at seat 1
- Put a plate at seat 2
- Put a fork at seat 2
- Put a napkin at seat 2
- Put a plate at seat 3
- Put a fork at seat 3
- Put a napkin at seat 3
- Put a plate at seat 4
- Put a fork at seat 4
- 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:
- Put a plate at the next seat
- Put a fork at the next seat
- 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?
- Put a sticker on page 1
- Put a sticker on page 2
- Put a sticker on page 3
- Put a sticker on page 4
- Put a sticker on page 5
- Put a sticker on page 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:
- Clap your hands
- Clap your hands
- Clap your hands
- Clap your hands
- Clap your hands
- Clap your hands
Challenge 2:
- Draw a line
- Turn right
- Draw a line
- Turn right
- Draw a line
- Turn right
- Draw a line
- Turn right
Challenge 3:
- Water the first plant
- Move to the next plant
- Water the first plant
- Move to the next plant
- Water the first plant
- Move to the next plant
- Water the first plant
- Move to the next plant
- Water the first plant
- 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?
2. What does "the lazy programmer" mean?
3. What is the difference between a "count loop" and an "until loop"?
Key Takeaways
- Writing the same instruction over and over is inefficient and leads to mistakes
- Loops let you write a set of steps once and repeat them as many times as you need
- The "lazy programmer" finds smart shortcuts -- and loops are the best shortcut
- There are two kinds of loops: count loops (repeat a set number of times) and until loops (repeat until something changes)
- Loops make instructions shorter, cleaner, and less likely to have mistakes
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 3Module Progress
You have completed Lesson 2! Two more lessons to go in Module 5.