GCSE · Computer Science · AQA · Spec 8525

Logic errors

Picture a sat nav giving clear, confident directions all the way to the wrong town. No beep, no warning light. 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.

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

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

Now break the rules instead

Same program, different kind of mistake.

Take the same loop program, but this time line 3 has been typed as WHILE (count < 5 with the closing bracket missing. What happens when you try to run it?

Two different kinds of mistake

Syntax errorvsLogic error

Start with the top row. It's the difference people mix up most.

Focus

Does the program run?

Syntax error

No. The code breaks the rules of the language, so the translator can't turn it into something the computer can run.

Logic error

Yes. Every line is legal, so it runs, often right to the end.

The insight

You have just seen both. A syntax error stops you before you start. A logic error lets you go all the way and still arrive at the wrong answer.

Who catches it?

Syntax error

The translator. It checks the code against the language's rules and reports the problem.

Logic error

Not the translator. It sees valid code and has no idea what you meant it to do, so it's up to you.

What you see

Syntax error

An error message, usually pointing at the line that broke a rule.

Logic error

A wrong output or the wrong behaviour. No message at all.

How you find it

Syntax error

Read the translator's error report and look at the line it points to.

Logic error

Work out the expected result first, then trace or test the program and compare.

A one-line example

Syntax error

OUTPUT "Area is (the closing quotation mark is missing, so the line breaks the rules)

Logic error

area ← length + width (legal code, but an area needs length × width)

No error message. So... is it right?

Your friend's program runs all the way to the end and prints a result. There's no error message anywhere.

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

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

  • Errors in programs come in different types. Syntax errors and logic errors are two of them.
  • A syntax error breaks the rules of the language, so the code can't be translated and run until it's fixed.
  • A logic error is valid code that runs but does the wrong thing, such as giving the wrong output.
  • Logic errors are found by comparing what the program actually does with the result you expected.

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

1No error message only rules out syntax errors. It doesn't prove the program is correct.
2The translator checks the rules of the language, not the meaning, so it can't spot a logic error.
3Decide the expected result before you trace or test. Without a target, a wrong answer looks fine.
4A computer does exactly what the code says. A logic error means the code says the wrong thing.

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?
A mistake in valid code: the program runs, but it does the wrong thing, such as giving the wrong output.
What is a syntax error?
Code that breaks the rules of the programming language, so it can't be translated and run until it's fixed.
A program runs with no error message. What does that prove?
Only that it has no syntax errors. It could still contain a logic error.
Why can't the translator detect a logic error?
Every line follows the language's rules. The translator can't know what the programmer meant the code to do.
How do you find a logic error?
Work out the expected result, then trace or test the program and compare the actual result with it.
What is a dry run?
Working through a program by hand, line by line, recording each variable's value in a trace table.

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.