GCSE · Computer Science · AQA · Spec 8525

Identifying and categorising errors

The scariest bug isn't the one that stops your program. It's the one that lets it run, look completely fine, and quietly hand you the wrong answer.

Computer Science · Categorising errors

Two questions sort any error

Pick an error in your head (a missing bracket, say, or < typed where <= was meant) and walk it down the tree. Each question sends it one way only.

Will it translate? → Does it give the right answer?

  • Start with the rules of the language. The code has to be translated before the program can run at all.

3 possible routes.

On An error in a program. 2 branches to choose from.

The questions come in this order for a reason: until the code translates, there's no program to test.

Build the grid

What each case actually looks like

Tick every property that's true for each program. Take your time with the one that has no errors. It's the one that catches people out.

Program with a syntax error
Program with a logic error
Program with no errors

Computer Science · Algorithms

Trace table — dry run the code

This program should add up every whole number from 1 to n. Our test: n = 4, so the expected output is 1 + 2 + 3 + 4 = 10. It translates and runs without a murmur. Step through and catch the moment it goes wrong.

1n ← USERINPUT
2total ← 0
3i ← 1
4WHILE i < n
5 total ← total + i
6 i ← i + 1
7ENDWHILE
8OUTPUT total
n
total
i
i < n
Output
Press Start to run the first line.
·

Ready when you are — step through one line at a time.

What do you think?

It runs, so is it finished?

Maya's program translates first time and runs without a single error message. She closes her laptop and announces: "Done. It works."

Which is closest to what you think right now?
How sure are you?

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

Two questions sort any program error: will it translate, and does it give the right answer?

What you need to know

  • Every program error goes into a category, based on what causes it and how it shows up.
  • There are two main categories to know: syntax errors and logic errors.
  • A syntax error breaks the grammar rules of the programming language you're writing in.
  • Typical culprits: a misspelt keyword, a missing bracket or colon, or a string that never gets its closing quote.
  • Have a goYour friend types OUTPT "Hello" instead of OUTPUT "Hello", and insists the computer is "just being fussy". Which category of error is it?

    A syntax error.

    OUTPT isn't a keyword in the language, so a grammar rule is broken. It isn't a logic error, because the thinking behind the line was fine; only the spelling broke the rules.

  • Code with a syntax error can't be translated, so the program won't run. The translator usually reports the error and its line.
  • A logic error is a mistake in the design or reasoning: < instead of <=, the wrong variable, or steps in the wrong order.
  • With a logic error the program runs but gives an incorrect or unexpected result, and the translator reports nothing.
  • Have a goA program should output the area of a rectangle, but its line says area ← length + width instead of length × width. Will the translator complain?

    No. It's a logic error, so nothing is reported.

    length + width is perfectly legal code. The mistake is the wrong operator, a slip in the reasoning, so the program runs happily and gives the wrong area.

  • Logic errors are found by testing: use test data whose expected output you know, then compare actual with expected.
  • Have a goSame buggy area program (it adds instead of multiplying). You test it with length 3 and width 5. What's the expected output, and what will it actually output?

    Expected 15; actual 8.

    Work out the expected answer by hand first: 3 × 5 = 15. The buggy line does 3 + 5 = 8. Without knowing the 15, you'd have no way to tell the 8 is wrong.

  • If they don't match, trace the code, for example with a trace table, to find where the values go wrong.
  • The fix: correct the rule-breaking code for a syntax error, or change the faulty logic so the program gives the intended result.

The big picture

Program errors come in two main categories, and you sort them by how they show up. Break the language's rules and the translator refuses the code: that's a syntax error, and you fix the rule-breaking code. Get the rules right but the thinking wrong, and the program runs but gives the wrong result: that's a logic error. The translator says nothing about it, so you find it by testing against an expected output and tracing, then change the faulty logic.

Key points

1Ask two questions, in order: will the code translate, and does it give the right answer?
2Translator refuses it → syntax error → fix the rule-breaking code.
3Runs but gives the wrong result → logic error → find it by testing and tracing, then change the faulty logic.
4A program that runs has no syntax errors. That tells you nothing about logic errors.

Worked example

Problem

A program should output the larger of two numbers, a and b. It contains the line IF a < b THEN OUTPUT a ELSE OUTPUT b. It is tested with a = 3 and b = 8. Categorise the error, and say how it would be found and fixed.

⚠ Watch out

Writing that a logic error means 'the program doesn't work'. That's too vague to show you understand it. Say what actually happens: the program runs, the output is wrong, and the translator reports nothing.

🧠

Memory hook

Syntax is the spelling and grammar of code; logic is the thinking behind it. The translator is a grammar checker, not a mind reader.

✓

Check yourself

Cover the page. An IF line is missing the colon its language needs: which category, and what does the translator do? Colon fixed, but it tests the wrong variable: which category now, and how would you find it?

Flashcards

(11)
What are the two main categories of program error?
Syntax errors and logic errors.
What is a syntax error?
A mistake that breaks the grammar rules of the programming language.
What happens when code contains a syntax error?
It can't be translated, so the program won't run. The translator usually reports the error and the line where it found it.
Give three examples of a syntax error.
A misspelt keyword; a missing bracket or colon; an unclosed string.
What is a logic error?
A mistake in the program's design or reasoning. The program runs but gives an incorrect or unexpected result.
Give three examples of a logic error.
The wrong operator (such as < instead of <=); the wrong variable; steps in the wrong order.
Why doesn't the translator report a logic error?
The code obeys every rule of the language, so there's no broken rule to report, and the translator can't know what result you meant.
How is a logic error found?
By testing: run the program with test data whose expected output you know, and compare the actual output with it.
A test gives the wrong result. How do you pin down where the logic error is?
Trace the code, for example with a trace table, following the values line by line until they stop matching what should happen.
How do you fix each kind of error?
Syntax error: correct the rule-breaking code. Logic error: change the faulty logic so the program produces the intended result.
A program runs with no error messages. What do you know for certain?
It has no syntax errors. It could still contain a logic error.

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 26 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.