GCSE · Computer Science · AQA · Spec 8525

Correcting errors

A program works out the average of 60, 60 and 90. No warnings, no crash, and it says 150. That's bigger than all three numbers. So what went wrong?

Syntax or logic?

Sort the faults

Pick a line, then choose its box. Ask one question: does it break the rules of the language, or does it follow the rules and do the wrong thing?

Still to sort

Syntax error (0)

Breaks the rules of the language. The translator can't translate it, so the program won't run.

Where the line is: It's about how the code is WRITTEN. Even if a human can see what was meant, the translator can't — it only accepts code that follows the rules exactly.

Logic error (0)

Follows every rule, so the program runs — but it does the wrong thing.

Where the line is: Every word and symbol is legal; it's the RESULT that's wrong. No error message will warn you, so you only find it by testing.

7 of 7 still to sort.

Each line was written by someone who meant well. The grey note under the code says what they wanted it to do.

Exam line: Name the type AND give the reason: "syntax — the keyword is misspelt, so it breaks the language's rules" or "logic — it runs, but > should be ≥, so 18 is wrongly left out".
Watch out: The line number a translator gives you is a clue, not a promise. A missing bracket is sometimes reported on the line AFTER, because that's where the translator finally realises something is wrong.

What does "no errors" really mean?

It ran first time. Job done?

Priya writes a program to work out the total cost of a shopping list. She runs it and it works first time: no error messages, no crash, a number appears on the screen.

What does that tell her? Pick the idea closest to what you think right now.
How sure are you?

Hunting a logic error

Test it, then trace it

This program should add up every whole number from 1 up to the limit you type in. It runs with no error messages. Let's see if it's right.

Test data: limit = 4. Expected output: 1 + 2 + 3 + 4 = 10. Step through — which row is the first to go off course?

1 INPUT limit
2 total ← 0
3 n ← 1
4 WHILE n < limit
5 total ← total + n
6 n ← n + 1
7 ENDWHILE
8 OUTPUT total
limitnn < limit?total
4

Output

 

Step 1: Before running anything, we worked out the answer by hand: 1 + 2 + 3 + 4 = 10. That's the expected output. Now we trace and compare.

1 / 14

Use Next to move one line at a time. Before each step, predict the value, then check.

Step 1 of 14: Before running anything, we worked out the answer by hand: 1 + 2 + 3 + 4 = 10. That's the expected output. Now we trace and compare..

Watch out: The wrong output appears on the last line, but that isn't where the mistake is. OUTPUT total is fine. It's faithfully showing a total that went wrong earlier. Find where it FIRST went wrong.

Spot the bug

Which line is wrong?

This program should input three marks and output their total. Tested with the marks 5, 7 and 8, it outputs 8 instead of 20. Pick the line that causes the problem.

A program with one bug — which line goes wrong?

Exam line: To correct an error, give the line, what's wrong with it and the fixed version, and check your fix with the same test data.

Your turn to explain

Name it, explain it, fix it

hours ← minutes * 60

A program should convert a number of minutes into hours. It contains the line below. State the type of error in this line, explain why it is that type of error, and write the corrected line. [4 marks]

0 words · your answer stays on this page and is not sent anywhere.

Exam line: "It's wrong" earns nothing on its own. Say WHICH type, WHY it's that type, and WHAT the line should be.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

How to tell which one you're facing, track it down, and fix it.

What you need to know

  • A syntax error breaks the rules of the programming language (for example a misspelt keyword, a missing bracket or a missing quotation mark). The code can't be translated, so the program won't run.
  • A logic error follows the rules, so the program runs, but it gives the wrong result or does the wrong thing.
  • The translator reports syntax errors, often with a line number. It can't report logic errors, because it doesn't know what you meant the program to do.
  • Logic errors are found by testing (comparing the actual output with the expected output) and by tracing (following the values line by line).
  • To correct an error, identify the line, say which type of error it is and why, and write the corrected line. Then test again.

The big picture

Programs go wrong in two main ways. A syntax error breaks the rules of the programming language, such as a misspelt keyword or a missing bracket. The translator can't translate it, so the program won't run until it's fixed, and the translator reports the error, often with a line number. A logic error follows every rule, so the program runs, but it does the wrong thing. No error message warns you, so logic errors are found by testing with data whose correct result you already know, and by tracing the program to see where the values first go wrong. Then you correct the line and test again.

Key points

1Breaks the rules → syntax error → won't run → the translator tells you.
2Follows the rules but gets it wrong → logic error → runs → only testing and tracing find it.
3No error messages does not mean a correct program.
4Work out the expected output BEFORE you run a test, then compare it with the actual output.
5In a trace, the error is where the values first go wrong, not where the wrong answer is finally shown.

Worked example

Problem

This program should output the larger of two numbers. It contains one syntax error and one logic error. Find both, say which type each is, and correct them. 1 INPUT a 2 INPUT b 3 IF a < b THEN 4 OUTPUT a 5 ELSE 6 OUPUT b 7 ENDIF

⚠ Watch out

Writing "it's wrong" without saying why. For a syntax error, name the rule it breaks (a misspelt keyword, a missing bracket). For a logic error, say what the line actually does and what it should do instead.

🧠

Memory hook

Think of the translator as a spell-checker for code. A spell-checker catches "Wensday", but it happily accepts "See you on Tuesday" when you meant Wednesday. Rule-breaking gets caught (syntax); a wrong meaning slips straight through (logic).

✓

Check yourself

Without looking back: what makes an error syntax rather than logic, and which one does the translator report? If a program runs but gives a strange answer, how would you find the faulty line?

Flashcards

(11)
What is a syntax error?
A mistake that breaks the rules of the programming language. The code can't be translated, so the program won't run.
What is a logic error?
A mistake that follows the language's rules, so the program runs, but it gives the wrong result or does the wrong thing.
Which type of error does the translator report?
Syntax errors, often with a line number.
Why can't the translator find logic errors?
It only checks that the code follows the language's rules. It doesn't know what the program is supposed to do.
Give three mistakes that cause syntax errors.
A misspelt keyword (OUPTUT), a missing bracket, a missing quotation mark.
Give three mistakes that cause logic errors.
The wrong comparison operator (> instead of ≥), a missing pair of brackets in a calculation, a loop condition that stops too early or never runs.
What is the expected output of a test?
The result the program SHOULD give for the test data, worked out by hand before the program is run.
How does a trace table help you find a logic error?
It records each variable's value line by line, so you can find the first row where a value differs from what should happen.
A program runs with no error messages. What can you conclude?
It has no syntax errors. It could still contain logic errors, so it needs testing.
Is a spelling mistake inside quotation marks a syntax error?
No. Text in quotes isn't checked by the translator. The program runs but shows the wrong message, so it's a logic error.
You've corrected a logic error. What should you do next?
Run the same test again and check the actual output now matches the expected output.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 30 September 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.