You’re offline. Saved pages still work

‹ Back to activities

Technology / Class 4–8 / 15 min / Medium

Coding Loops and Conditions: Guide the Robot

Understand that a program is a sequence carried out in order, that a loop repeats the commands inside it, that a condition is checked while the program runs, and that debugging means finding the line that goes wrong.

Before you try

What if you had to write "move forward" ten times in a row? Is there a shorter way?

Try it out

Interactive activity

Loading simulator…

Loading controls…

What happened?

Move a control to see what changes and why.

The robot does exactly what it is told, instantly and without error. Real robots have sensors that misread and motors that slip.

Try these ideas

  • Solve level 1 with plain moves, then rewrite it using a repeat block.
  • Use Step to run one instruction at a time and watch the highlighted line.
  • On level 3, plan a route that collects all three coins before the star.

Why it works

A computer does exactly what it is told, in the order it is told, and nothing more. That is a sequence. A loop saves you repeating yourself: writing "repeat 4 times, move forward" is four moves in two lines, and if you change the number the whole behaviour changes. A condition such as "if there is a wall ahead, turn right" is tested at the moment the robot reaches it, so the same program can cope with different mazes.

When a program goes wrong, the skill is not guessing but debugging: running it step by step to find the exact line that misbehaves. In this simulator the robot stops at the line that drove into a wall and highlights it for you. Three mazes get harder, the last one adding coins to collect, and each has a par so you can try to solve it in fewer commands.

Check your understanding

Question 1 of 4

What does a loop do in a program?

When is a condition like "if wall ahead" checked?

Your robot bumps into a wall on line 5. What should you do first?

Which program moves the robot four squares forward?

Explain it in your own words

What changed? Why did it happen? Where might you notice this in everyday life?

What will you discover next?

Try Binary Numbers: Count with Zero and One next.

Continue learning

For parents & teachers

  • Give each other step-by-step directions across a room and follow them exactly.
  • Ask where loops would help in a daily routine, like brushing every tooth.
  • Discuss what a robot vacuum does when it meets a wall.

Open the parent & teacher guide ›

Explore all activities ›

Install GoKuriousPlay offline from your home screen.