Don't Repeat Yourself
In Lesson 4 you needed 8 blocks to draw a square — the same 2 blocks repeated 4 times. A loop lets you write those 2 blocks once and say "repeat 4 times."
Programmers have a rule: Don't Repeat Yourself (DRY). If you are writing the same thing over and over, there is almost always a smarter way — and that smarter way is called a loop.
📌
What Is a Loop?
A loop is a section of code that runs automatically a certain number of times. Instead of writing 8 blocks for a square, you write 2 blocks and tell the program to repeat them 4 times.
Spirals and Surprises
Loops open up shapes that would take hundreds of blocks to build by hand. Try this:
- Program: Move Forward 10 → Turn Right 90°
- Set Repeat to 20
What do you think it will draw? Run it and see! Now try changing the step size or repeat count and see how the shape changes.
⭐
Loops in the Real World
Video games use loops constantly. Every frame of a game — your character moving, enemies thinking, the score updating — happens inside a giant loop running 60 times per second. Without loops, games could not exist!