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.
Each line was written by someone who meant well. The grey note under the code says what they wanted it to do.
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 limit2 total ← 03 n ← 14 WHILE n < limit5 total ← total + n6 n ← n + 17 ENDWHILE8 OUTPUT total
| limit | n | n < 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.
Use Next to move one line at a time. Before each step, predict the value, then check.
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
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?
What is a logic error?
Which type of error does the translator report?
Why can't the translator find logic errors?
Give three mistakes that cause syntax errors.
Give three mistakes that cause logic errors.
What is the expected output of a test?
How does a trace table help you find a logic error?
A program runs with no error messages. What can you conclude?
Is a spelling mistake inside quotation marks a syntax error?
You've corrected a logic error. What should you do next?
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 postedMore AQA GCSE Computer Science topics
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.