Debugging programs: 11+ computing lesson and practice questions
A video lesson, the method for finding and fixing the mistake in any program, the mistakes children make most, and 10 practice questions with worked answers.
Wider curriculumComputingYears 5 and 6Free, no sign-up
To debug a program, run it in your head one step at a time and find the first step where it stops
doing what it should. Make one change there, then run the whole program again to test that the fix works.
For example, a robot facing up that should end two squares to its left is told "turn right, forward 2". The
first step that goes wrong is the turn, so the fix is "turn left".
Video lesson: debugging programs
5 minutes 49 seconds. Captions are shown in the video, and the full transcript is below.Read the video transcript
Hi there! Today we're learning to debug: to find the mistake in a program and fix it.
This robot starts on E5, facing down, and should stop on the star at A3, but it drives off the edge: which one change fixes it? Turn left: facing down, its left is the page's right, so it faces right; forward 4: onto F5, then off the edge, but line 1 went wrong first. So the answer is: change line 1 to turn right. Check: facing left, forward 4 to A5; turn left, facing down; forward 2 to A3, the star.
This robot starts on B6, facing right, and should stop on the star at D2, but it stops on D3: which one change fixes it? Turn right, facing down; forward 3 to B3; turn left, facing right; forward 2 to D3, facing right: one square too high, so line 2 must move down 4. So the answer is option A: change line 2 to forward 4. Option B ends on E3, option C on D1, and option D drives off the edge.
This robot starts on C6, facing left, and should stop on the star at F1, but it stops on E2: which one change fixes it? Forward 2 to A6, turn left to face down; each pass goes one down, one right, ending on E2, facing down, but the star is five down and five right, so it needs five passes. So the answer is: change line 3 to repeat 5. If each pass is the wrong size, change a forward inside the brackets.
This script should say "Open chute" only when the answer is more than 42: which change makes the script pass every test? Run every test: as printed, 43 says "Keep climbing" and 37 says "Open chute", both wrong. With "more than", 43 says "Open chute", and 42 and 37 say "Keep climbing": every test passes. So the answer is option B: change "less than" to "more than". The swap fails on 42, the number on the line, so test it too; options C and D fail on 43. If it already says "more than" but the messages are swapped, swap them.
This flowchart should output 25, 50, 75 and 100, but it only outputs 25, 50 and 75: which change fixes it? After 75, add 25: 100 is not less than 100, so it ends. So the answer is option D: change "Is n less than 100?" to "Is n less than 125?". Option B goes too far, to 125; option A adds a 0; option C stops after 25. If the first number is wrong instead, change the "Set n" box to the first number it should output.
Your turn: this script should say "Bus is full" only at the right times: which change makes the script pass every test? Pause the video and run every test. Option C moves the number to 49: 50 says "Bus is full", and 49 and 46 say "Hop on". So the answer is option C: change 48 to 49. Option B still says "Bus is full" for 49; options A and D fail on 50.
Let's review: find the first line that goes wrong, then make one change and test it. A fix must pass every test, even the number on the line. Well done! Now try some questions to show what you know.
The method in four steps
Know what it should do. Read where the robot should stop, what the script should say for each test, or which numbers the flowchart should output.
Trace it as printed. Follow the program one line at a time and write down where it is after each line: the square and the way the robot faces, the message for each test, or the value of n.
Find the first line that goes wrong. The bug is where the trace first stops matching what should happen. A change near the end rarely mends a mistake made earlier.
Make one change and test again. Make the change, then trace the whole program again from the start. A fix only counts if it works for everything: the right square, every row of the test table, every number.
On a robot grid, columns are letters and rows are numbers, with row 1 at the bottom. "Turn left"
and "turn right" are a quarter turn to the robot's own left or right, on the same square, so a robot facing down
turns towards the page's right when it turns left. In a repeat, decide whether each pass is the
wrong size (change a forward inside the brackets) or the right size done too few or too many times (change the
repeat number). In a script with if and else, check each test row, especially the number on the
line itself: "more than 20" does not include 20. In a flowchart with a loop, a wrong first number
points to the box that sets n, and a loop that stops too early or runs too far points to the question box. For
example, "Set n to 7, Output n, Add 7 to n, Is n less than 27?" outputs 7, 14 and 21, then stops, because 28 is
not less than 27. To output 28 as well, the question must let 28 through but stop 35, so "Is n less than 35?"
works.
Worked examples
Example 1: a wrong turn
A robot starts on E1, facing up, on a 6 by 6 grid. It should finish on the star at C3. Its program is: forward 2, turn right, forward 2. Where does it go wrong, and what is the fix?
First line: forward 2 takes it to E2, then E3. That is the right row.
Second line: turn right. Facing up, its right is the page's right, so it now faces right. The star is to the left, so this is the first line that goes wrong.
Last line as printed: F3, then off the right edge of the grid.
Fix: change the turn to turn left. Test: up to E3, turn left to face left, then D3 and C3. It stops on the star.
Example 2: the wrong number of repeats
A robot starts on B1, facing right. It should finish on the star at F5. The program is: repeat 2 [ forward 1, turn left, forward 1, turn right ]. It stops on D3. What is the fix?
Pass 1: forward 1 to C1, turn left to face up, forward 1 to C2, turn right to face right again.
Pass 2: D2, then up to D3, facing right. Each pass moves 1 right and 1 up, which is the right shape.
From the start to the star is 4 squares right and 4 up, so the pattern must run 4 times, not 2. The steps inside are fine; the count is wrong.
Fix: change the repeat number from 2 to 4.
Test: the two extra passes go up to E4, then on to F5, the star. (Adding a forward at the end could not reach F5, because the star is both right and up from D3.)
Example 3: testing the number on the line
A script asks "What is the temperature?" and should say "Time for a coat" only when the answer is less than 12. It reads: if answer is less than 11 then say "Time for a coat", else say "No coat needed". The tests are 9, 11 and 12. Which change makes every test pass?
Test 9: 9 is less than 11, so "Time for a coat". Correct.
Test 11: 11 is not less than 11, so "No coat needed". Wrong, because 11 is less than 12 and should get "Time for a coat".
Test 12: 12 is not less than 11, so "No coat needed". Correct.
Fix: change 11 to 12. Test again: 9 and 11 are less than 12, so "Time for a coat"; 12 is not, so "No coat needed". All three pass. Swapping the two messages would fail on 9 and 12.
Common mistakes
Mending the end instead of the cause. Adding a move after the last line looks tempting, but the robot may be facing the wrong way by then. Find the first line that goes wrong.
Using the page's left instead of the robot's left. A robot facing down that turns left ends up facing the page's right. Turn the page, or your hand, to match the robot.
Testing only one row. A change can fix one test and break another. Check every row of the table, and especially the number on the line.
Forgetting that "more than" leaves out the number itself. "More than 40" is false for 40, so 40 goes to the else part of the script.
Changing the inside of a loop when the count is wrong, or the other way round. If each pass is the right shape but there are too few of them, change the repeat number.
Over-correcting. Moving a number too far makes a loop run one pass too many. Trace to the end to check that nothing extra is output.
10 practice questions with answers
Tap an answer to check it, or open the worked answer. The questions start simple and finish at the level of a harder 11+ question. In the robot questions, row 1 is at the bottom of the grid.
1.A beach-cleaning robot starts on A3, facing right. This program should make it stop on the star at B1. Instead it stops on B5. Which ONE change fixes the program?
Change line 3 to forward 1
Change line 1 to forward 2
Change line 2 to turn right
Change line 3 to forward 3
Show the answer
Change line 2 to turn right. As printed, the robot moves to B3, then turns left. Facing right, its left is up, so it goes B4, B5. The star is below, so line 2 is the first line that goes wrong. With turn right it faces down and goes B2, B1, onto the star. Changing line 3 cannot help while the robot faces up: forward 3 would take it off the top of the grid.
2.This script should say "Goal reached" only when the answer is more than 18. The table shows what it should do. Which change makes the script pass every test?
Change 18 to 17
Swap "Keep walking" and "Goal reached"
Change "more than" to "less than"
Change 18 to 23
Show the answer
Swap "Keep walking" and "Goal reached". As printed, 19 is more than 18, so the script says "Keep walking", and 18 is not, so it says "Goal reached". Both are the wrong way round: the test is right but the messages are on the wrong branches. After the swap, 19 gives "Goal reached" and 18 gives "Keep walking". Changing "more than" to "less than" fixes 19 but makes 18 say "Goal reached".
3.This script should say "Too hot" only when the answer is more than 32. The table shows what it should do. Which change makes the script pass every test?
Change 32 to 31
Change 32 to 33
Swap "Too hot" and "OK"
Change "less than" to "more than"
Show the answer
Change "less than" to "more than". As printed, 35 is not less than 32, so the script says "OK", which is wrong. With "more than", 35 is more than 32, so it says "Too hot", and 32 is not more than 32, so it says "OK". Both tests pass. Swapping the messages fixes 35 but makes 32 say "Too hot", and changing the number alone still leaves 35 saying "OK".
4.This script should say "Too noisy" only at the right times. The table shows what it should say for each answer. Which change makes the script pass every test?
Change 70 to 71
Change "more than" to "less than"
Change 70 to 69
Swap "Too noisy" and "Quiet enough"
Show the answer
Change 70 to 71. Run each test as printed: 69 gives "Quiet enough" (right), 72 gives "Too noisy" (right), but 71 is more than 70, so it gives "Too noisy" (wrong). The table wants 71 to be quiet enough, so the line must be at 71. With "more than 71", 69 and 71 give "Quiet enough" and 72 gives "Too noisy". Changing 70 to 69 keeps 71 wrong, and the other two options break 69 and 72.
5.A rover on a model Mars base starts on E2, facing left. This program should make it stop on the star at E5. Instead it stops on E4. Which ONE change fixes the program?
Change line 4 to turn left
Add forward 1 as a new last line
Change line 3 to forward 4
Change line 3 to forward 3
Show the answer
Change line 3 to forward 3. As printed: D2, C2, then turn right (facing left, its right is up), C3, C4, turn right to face right, D4, E4. It ends one row too low, and the move up is line 3. With forward 3 it goes C3, C4, C5, then right to D5, E5, the star. Adding forward 1 at the end moves it right to F4, because it faces right by then. Forward 4 ends on E6.
6.A robot waiter in a cafe starts on D6, facing down. This program should make it stop on the star at B6. Instead it stops on B5. Which ONE change fixes the program?
Change line 5 to forward 2
Change line 5 to forward 3
Change line 3 to forward 1
Change line 3 to forward 3
Show the answer
Change line 5 to forward 2. As printed: D5, D4, then turn right (facing down, its right is the page's left), C4, B4, turn right to face up, B5. Everything is right until the last move, which is one square short. With forward 2 it goes B5, B6, the star. Forward 3 would take it off the top edge, and changing line 3 puts it in the wrong column.
7.This flowchart should output 30, 40, 50, 60 and 70. Instead it outputs 40, 50, 60 and 70. Which change fixes it?
Change "Is n less than 80?" to "Is n less than 90?"
Change "Add 10 to n" to "Add 9 to n"
Change "Set n to 40" to "Set n to 30"
Change "Set n to 40" to "Set n to 39"
Show the answer
Change "Set n to 40" to "Set n to 30". The first number output is the number n is set to, so the first output is wrong because n starts at 40. Starting at 30, it outputs 30, 40, 50, 60 and 70; then 70 + 10 = 80, and 80 is not less than 80, so it ends. "Less than 90" still starts at 40 and adds 80. Starting at 39 gives 39, 49 and so on. Adding 9 gives 40, 49, 58 and so on.
8.This flowchart should output 6, 9, 12, 15 and 18. It only outputs 6, 9, 12 and 15. Which change fixes it?
Change "Is n less than 18?" to "Is n less than 23?"
Change "Is n less than 18?" to "Is n more than 18?"
Change "Is n less than 18?" to "Is n less than 21?"
Change "Set n to 6" to "Set n to 7"
Show the answer
Change "Is n less than 18?" to "Is n less than 21?" After 15 is output, 15 + 3 = 18, and 18 is not less than 18, so the loop ends one pass early. With "less than 21", 18 goes round and is output; then 18 + 3 = 21, and 21 is not less than 21, so it ends. "Less than 23" goes too far: 21 is less than 23, so 21 is output too. "More than 18" stops after 6, and starting at 7 gives 7, 10, 13 and 16.
9.A snowplough in a game starts on A1, facing right. This program should make it stop on the star at B3. Instead it stops on D3. Which ONE change fixes the program?
Change line 2 to repeat 4
Change line 3 to forward 1
Add forward 1 as a new last line, after the repeat bracket
Change line 2 to repeat 3
Show the answer
Change line 2 to repeat 3. Line 1 takes it to B1. Pass 1: C1, D1, then turn left to face up. Pass 2: D2, D3, then turn left to face left. Each pass is the right size, but the robot needs one more: pass 3 goes C3, B3, onto the star (it then turns on the same square). Repeat 4 goes on to B2 and B1. Adding forward 1 at the end stops on C3, one square short.
10.A beach-cleaning robot starts on B5, facing down. This program should make it stop on the star at D3. Instead it stops on F3. Which ONE change fixes the program?
Add forward 1 as a new last line, after the repeat bracket
Change line 2 to forward 2
Change line 3 to turn right
Change line 4 to forward 1
Show the answer
Change line 4 to forward 1. As printed, pass 1: B4, turn left (facing down, its left is the page's right), C4, D4, turn right to face down. Pass 2: D3, turn left, E3, F3. Each pass moves 1 down and 2 right, but the star is 2 down and 2 right of B5, so each pass needs 1 down and 1 right. With forward 1 in line 4: B4, C4, then C3, D3, the star. Adding forward 1 at the end moves down to F2, because the robot faces down by then.
Want more debugging practice?
Inside ElevenReady your child gets hundreds more computing questions at the right level, a short lesson
before each new skill, and a parent dashboard that shows which skills are secure and which need work.
Start with 30 days free. No card needed.
Schools whose 11+ includes wider-curriculum questions
Wider-curriculum questions, which can draw on any Key Stage 2 subject, are part of the FSCE test used by the
Gloucestershire grammar schools below, and computing questions like these are practice for that breadth.
GL-style tests do not include them, so most children sitting a GL test will not see a debugging question. The schools, with the subjects our school directory lists:
Sir Thomas Rich's SchoolGloucester. FSCE: English, Maths and questions across the wider curriculum
Denmark Road High SchoolGloucester. FSCE: English, Maths and questions across the wider curriculum
Ribston Hall High SchoolGloucester. FSCE: English, Maths and questions across the wider curriculum
Marling SchoolStroud. FSCE: English, Maths and questions across the wider curriculum
Stroud High SchoolStroud. FSCE: English, Maths and questions across the wider curriculum
The Trafford grammar schools move from GL to FSCE for 2028 entry; check each school's admissions page for
whether its papers include wider-curriculum questions.
Subjects taken from our school directory in November 2026. Exam arrangements change, so
always check the school's own admissions page for the year your child applies.
Questions parents ask
What does debugging mean?
A bug is a mistake in a program that makes it do the wrong thing. Debugging means finding the mistake and fixing it. Children do it by running the program in their head, one step at a time, and noticing the first step where it stops doing what it should.
Does my child need a computer to practise debugging?
No. In 11+ questions the program is printed in the question, so the skill is tracing it by hand. A pencil, a squared grid and a short program are enough. Free block-coding tools such as Scratch are a good way to see programs run, but they are not needed for the test.
When do children learn debugging at school?
In England, children start in Key Stage 1, where the computing curriculum asks them to create and debug simple programs. In Key Stage 2 they design, write and debug programs that use sequence, selection and repetition, and use logical reasoning to find and correct errors in algorithms and programs.
Is debugging tested in the 11+?
Only in tests that include wider-curriculum questions, such as the FSCE test used by some Gloucestershire grammar schools. GL-style tests of English, maths and reasoning do not ask computing questions.