Debugging: Finding & Fixing Mistakes (Year 4–5)

💻 Computer Science Years 4–5 Foundation

A bug is a mistake in your steps. Debugging means testing your steps, spotting where they go wrong, fixing them, and testing again.

Open this lesson, with practice and a printable worksheet →

Sometimes an algorithm does not work. There is a mistake hidden in the steps. We call that mistake a bug. Finding and fixing a bug is called debugging.

Why this matters: Everyone makes mistakes, even the best coders. What matters is being able to find the mistake, calmly and carefully, and put it right. Debugging teaches patience and careful checking.

Test, spot, fix, test again

Debugging has a simple pattern you can use for anything:

StepWhat you do
1. TestRun through the steps and see what happens.
2. SpotFind the exact step where it goes wrong.
3. FixChange that step to make it right.
4. Test againRun through it once more to check it works.

A buggy algorithm

This "getting dressed" algorithm has a bug: the shoes go on before the trousers, so the trousers get stuck! A good bug-hunter reads through the steps slowly, one at a time, until they spot exactly where it goes wrong.

Put these steps in the correct order to get dressed:

  1. Put on your socks
  2. Put on your trousers
  3. Put on your shoes

Being a good bug-hunter

Good debuggers go slowly and check one step at a time. They do not rush. When they think they have fixed it, they always test again, because sometimes a fix makes a new bug! Debugging is a skill every coder uses, again and again, every time they write something new.

TestSpotFixTest!
Get the printable worksheet →
← Algorithms: Clear Step-by-Step Instructions (Year 3–4) → Block Coding: Sequences & Events (Year 3–4)
← Sasta Basta home All subjects