GCSE · Computer Science · AQA · Spec 8525
Logic errors
Picture a sat nav giving calm, confident directions all the way to the wrong town. No beep. No warning light. Just the wrong place. That's a logic error.
Computer Science · Algorithms
Trace table — dry run the code
This program should add up 1 + 2 + 3 + 4 + 5 and output 15. Be the computer: step through it line by line and see what it really does.
Ready when you are — step through one line at a time.
Now break the rules instead
Same program. Different kind of mistake.
Take the loop program you just traced, but this time the WHILE line has been typed as WHILE (count < 5 with the closing bracket missing. What happens when you try to run it?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
The program runs. No error message. And the answer is still wrong.
What you need to know
- Programs can go wrong in different ways. The two types here: syntax errors and logic errors.
- A syntax error breaks the rules of the programming language, like a bracket opened and never closed.
- Code with a syntax error can't be translated, so it won't run until it's fixed.
- Instead of an output, you get an error message, usually pointing at the broken line.
Have a goYour mate types OUTPUT "Hello and forgets the closing quotation mark. They hit run and wait, smiling, for Hello to appear. What actually happens?
No Hello. The code won't run, and an error message appears instead.
A missing quotation mark breaks the language's rules, so the code can't be translated. Waiting longer won't help: nothing runs until it's fixed.
- Logic errors play by the rules: every line is legal, so the program runs.
- It just does the wrong thing, such as giving the wrong output, often with no crash and no warning.
Have a goOdd one out: a bracket never closed, a misspelt keyword, or a line that adds two lengths when it should multiply them to get an area?
Adding instead of multiplying.
The first two break the rules, so they're syntax errors. Adding is perfectly legal code that gives the wrong area, which makes it a logic error.
- Running without complaint is not the same as being right.
- To catch a logic error, decide the expected result first, then trace or test the program and compare.
Have a goYou're about to test a program that should halve a number. Before you type in 8, what do you need to have worked out?
That the right output is 4.
Without an expected result, a wrong output such as 16 looks just as believable as the right one, and the logic error slips straight past you.
The big picture
Programs can go wrong in different ways. A syntax error breaks the rules of the programming language, so the translator can't translate the code and reports the problem instead. A logic error is sneakier: every line is valid, the program runs, and it quietly produces the wrong result. You catch it by knowing what the result should be and checking.
Key points
Worked example
Problem
A program should output "Pass" for any score of 50 or more. It contains the line IF score > 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail". Is there an error? If so, what type?
⚠ Watch out
Thinking a program must be correct because it ran without an error message. That only tells you there are no syntax errors. It tells you nothing about logic errors.
Memory hook
Syntax is the grammar of code: break it and the translator complains straight away. Logic is the meaning: get it wrong and the program says nothing, it just gets the answer wrong.
Check yourself
A program should output "Too cold" for temperatures below 5. You enter 2: no output, no error message. Syntax error or logic error, and what's your evidence?
Flashcards
(6)What is a logic error?
What is a syntax error?
A program runs with no error message. What does that prove?
Why can't the translator detect a logic error?
How do you find a logic error?
What is a dry run?
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
- Integer division and remainder
- Iteration
- Keyboard input
- Less than (relational operator)
- Less than or equal to (relational operator)
- Local variables
- Meaningful identifier names
- Multiplication (arithmetic operator)
- Nested iteration
- Nested selection
- NOT (Boolean operator in code)
- Not equal to (relational operator)
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 29 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.