Algorithms and debugging

Learn about programming and debugging.

This lesson includes:

  • two videos to help you understand debugging
  • three activities to try out


Programmers write computer programs in a language we call code. However, sometimes there are problems and the program doesn't work properly. These are known as ‘bugs’.

A program can be made up of lots of lines of code and it is normal for new programs to have some bugs.

An important part of programming is testing your program and 'debugging' (which means removing the bugs).

Watch this short film to find out more about what a bug is.

In this video Nate looks at the difference between syntax errors and logic bugs.

Different types of bug

Syntax bugs

An error caused by something typed in the code – it could be a spelling mistake.

Logical bugs

The computer is able to carry out the instructions but the result isn't what the programmer intended or the user expects.

In this short film find out how to fix mistakes you might make when writing code.

Finding these mistakes and getting rid of them is really important and it is known as 'debugging'.

Debugging strategy

Let's imagine you have just created a new computer game in Kodu or Scratch. In the game, when you press the arrow keys your character moves around the screen trying to avoid an enemy - in this case an evil frog.

You want to show everybody your game because it looks great but you decide to check it works properly first.

When you run your program, the evil frog starts moving towards you but when you press the arrow keys, nothing happens. There must be a bug!.

Where do you start?

Do you look at all the programming for your game? Or do you look at the part of the program that isn't working properly?

Both options would work but a good debugging strategy would be to look for the part of the program that isn't working properly.

Rather than going through every individual line of code searching for an error, computer programmers try to think logically about where the problem might have occurred.

This is much more efficient.

In the game the character did not move when the keys were pressed. We can debug the game by looking at the code for character movement. The number of steps is set to 0, so that's why the character didn't move!

Debugging question

You've programmed a toy car to drive around a map, but when it reaches a house the car continues to drive through it!

Does your program have a syntax bug or a logical bug?

Your program has a logical bug.

A logical bug means that the program runs but doesn't do what the programmer intended. Here, the car is not turning when it is meant to.

A syntax bug is an error in the code which usually stops a program from working.

The car is moving, it’s just not going where it should... so the problem is probably not a syntax bug.


Activity 1

Try this World Cup algorithm programming adventure.

Plan a route through the grid to the World Cup. Write instructions using forward, left or right turn and how many degrees.

Then work with a partner to practise testing and debugging your algorithm.

Explore more computing resources with Teachit Primary.

World cup debugging

Activity 2

The worksheet gives you an activity to create and debug algorithms for a football game. You can develop your algorithms into code using Kodu.

Get more resources on computing and Kodu from Twinkl.

Football game for Kodu

Activity 3

Try these mini activities for home learning designed to help practise computational thinking skills.

Try more coding activities with Barefoot by BT and Computing At School.

Mini Missions for around the home

Where next?

In this lesson you have learnt about debugging.

Click on the links below to find out more:

There's more to learn

Bitesize Daily lessons
KS2 Computing
Play more Bitesize games
KS2 Computing
Practise coding with Scratch
Play CBBC games