Studyfin Studyfin ✨ Sign up free

Debugging

Grade 6 · Coding · Free lesson

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

Have you ever made a mistake while writing a recipe or drawing a picture? In coding, a mistake in your instructions is called a bug. Finding and fixing these mistakes is called debugging.

school

An algorithm is just a list of steps to finish a task. If the steps are in the wrong order, our program will get confused. To debug, we must check each step one by one.

Step 1Step 2Step 3

When we debug, we look for steps that are missing, out of order, or incorrect. Fixing a bug makes our code run perfectly!

✏️ Worked example

Let's debug an algorithm for making a peanut butter sandwich. The current steps are: 1. Spread peanut butter on the bread. 2. Eat the sandwich. 3. Put two slices of bread on a plate. Let's find the errors and fix them!

  1. Analyze the goal: We want to make a sandwich before we eat it.
  2. Identify the errors: Step 2 says to eat the sandwich before we even put the bread on the plate (Step 3). That is impossible!
  3. Rearrange the steps: Put the bread on the plate first.
  4. Add the next step: Spread the peanut butter on the bread.
  5. Finish the algorithm: Eat the sandwich as the final step. Now the bug is fixed!
code
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons