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.

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 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?

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've now 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. Your friend is already celebrating.

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

  • 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

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