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 confidently 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 find it by testing.
Each line was written by someone who meant well. The 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. Is it right? Let's find out.
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: a misspelt keyword, a missing bracket, or a punctuation slip like a missing quotation mark.
- Code with a syntax error can't be translated, so the program won't run until you fix it.
Have a goYour mate types OUTPT "Hi" and shrugs: "It'll run. The computer knows I meant OUTPUT." Will it run?
No. It won't run until the keyword is spelt correctly.
A misspelt keyword breaks the language's rules, so the code can't be translated. The translator never guesses what you meant.
- The translator (a compiler or interpreter) reports syntax errors, often with a line number.
- A logic error follows every rule, so the program runs. It just gives the wrong result or does the wrong thing.
- Classic logic errors: the wrong operator, like > where you needed ≥, or the wrong condition in a loop.
Have a goA countdown should print 3, 2, 1. It sets n ← 3, then loops WHILE n > 1, printing n and taking 1 off each time. What does it actually print?
3, 2, and then it stops.
When n reaches 1, 1 > 1 is False, so the loop ends before printing 1. Every line is legal, so it runs: it's the loop condition that's wrong (it should be n ≥ 1).
- The translator can't report logic errors, because it has no idea what you meant the program to do.
- So "no error messages" only means no syntax errors. It doesn't mean the program is right.
- Testing catches logic errors: choose test data, work out the expected output by hand, then compare it with the actual output.
Have a goYou're testing a program that should find the mean of 4 and 8. Before you press run, what do you write down?
The expected output: 6.
(4 + 8) / 2 = 6. If you look at the program's answer first, it's easy to accept whatever it prints, and a logic error slips straight past you.
- Tracing shows where it went wrong: follow each variable line by line in a trace table and find the first wrong value.
- To correct an error, name the line, say which type it is and why, write the fixed line, then test again.
The big picture
Programs go wrong in two main ways. A syntax error breaks the rules of the programming language, like 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. Nothing warns you. You find logic errors 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
- Character data type
- Concept of a data type
- Concept of subroutines
- Constant declaration
- Convert character code to character
- Convert character to character code
- Data validation routines
- Equal to (relational operator)
- Greater than (relational operator)
- Greater than or equal to (relational operator)
- Identifying and categorising errors
- Indefinite (condition-controlled) iteration
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 28 October 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.