Loop the Loop
Loading simulation…
flagWhat you'll discover
- arrow_forwardSpot repeating patterns in a path before coding it
- arrow_forwardUse the repeat block to run other blocks many times
- arrow_forwardSolve each maze using the fewest blocks possible
- arrow_forwardNest moves and turns inside one loop to walk a staircase
Why loops exist
Imagine telling the robot to walk 100 squares by stacking 100 move blocks — exhausting! Programmers are proudly lazy in a clever way: when work repeats, they wrap it in a loop and let the computer do the repeating. The repeat block runs everything inside it a chosen number of times. Six moves becomes "repeat 6: move" — two blocks instead of six. Real programs use loops constantly: drawing every pixel on your screen, checking every message in your inbox, playing every frame of a video.
Find the pattern first
The secret to using loops well is spotting the repeating pattern before you build anything. Look at the staircase maze: the robot does move, turn, move, turn... the same little dance over and over. Once you can say the pattern out loud — "move then turn left then move then turn right, three times" — translating it into a repeat block is easy. Pattern-spotting is a deep skill: scientists, mathematicians and programmers all hunt for patterns because one small rule can describe something huge.
Smaller programs are better programs
Each level shows a block-count challenge like "solve with 5 blocks or fewer". Why care, if a long program also works? Because shorter programs have fewer places for bugs to hide, are faster to read, and are easier to change later. Professional programmers spend much of their time making working code shorter and clearer — they call it refactoring. If your solution uses 12 blocks, ask yourself: what is repeating? Wrap it in a loop and watch your program shrink.