Some puzzles look hard until you spot the trick. In this Code.org challenge, Eon had to guide a character across a grid to reach the goal — and discovered one of the most powerful ideas in all of coding: the loop.

The puzzle: cross the grid

The first idea is to drop one move block at a time — east, east, east… It works, but the program gets long and messy fast. There had to be a tidier way.

The "aha": let the computer repeat

Instead of stacking the same block over and over, Eon used a repeat block — a loop. He counted the squares to the goal (three steps east) and set the loop to repeat 3 times. One block did the work of three!

A loop runs the steps inside it again and again. Change the number, and it repeats more or fewer times.

The whole program became short and neat:

  • move north
  • repeat 3 times: move east
  • move south

Four lines of code solved a puzzle that looked complicated.

Debugging with "Step"

When the path went wrong, Eon pressed Step instead of Run. Run does everything at once; Step does one block at a time, so you can watch exactly where the character turns the wrong way — then fix it. That's the same trick real programmers use to find bugs.

Why loops matter

Loops are everywhere in code. They let a tiny program do a huge amount of work. Any time you catch yourself writing the same thing again and again, that's a loop waiting to happen.

Try it: if the goal were 5 steps east instead of 3, what number would you put in the repeat block? (You've got it — 5!)