Studyfin Studyfin ✨ Sign up free

Debugging

Grade 3 · Coding · Free lesson

Hi there! I am Studyfin, your learning buddy. Today we will learn how to find and fix mistakes in code!

An algorithm is a list of steps to do a task. Sometimes, a step has a mistake. We call this mistake a bug. Finding and fixing these bugs is called debugging.

arduino

To debug, we must trace our code step by step. We look at each instruction like a detective. We check if it does what we want. If a step is wrong, we fix it.

Tracing the Path to Find the Bug

Once we find the bug, we remove it. Then we test our code again. If the path is clear, our program runs perfectly from start to finish!

Success! The Path is Clear
✏️ Worked example

A robot wants to take 3 steps forward to reach a shiny gold key. The code says: Step 1: Walk forward. Step 2: Turn left. Step 3: Walk forward. Explain how to find the bug and fix it so the robot gets the key.

  1. Analyze the goal: The robot needs to go straight for 3 steps to reach the key.
  2. Trace Step 1: The robot walks forward 1 step. This is correct.
  3. Trace Step 2: The robot turns left. Oh no! The key is straight ahead, not to the left. This is the bug!
  4. Remove the error: Replace 'Turn left' with 'Walk forward'.
  5. Trace Step 3: The original code said 'Walk forward'. This is correct for the final step.
  6. Test the new code: Walk forward, Walk forward, Walk forward. The robot successfully reaches the key!
code
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons