Skip to main content
EnglandComputer ScienceSyllabus dot point

What are syntax errors and logic errors, and how do you tell them apart?

The two main types of programming error: syntax errors and logic errors, what causes each, how they are found, and how they differ.

An OCR J277 2.3.2 answer on the two main types of programming error: syntax errors (breaking the rules of the language) and logic errors (the program runs but gives the wrong result), what causes each, and how they are found and corrected.

Generated by Claude Opus 4.89 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. Syntax errors
  3. Logic errors
  4. Telling them apart
  5. Try this

What this dot point is asking

OCR wants you to know the two main types of programming error, syntax errors and logic errors, what causes each, how they are found, and how they differ. The key distinction is that a syntax error stops the program running, while a logic error lets it run but produces the wrong result. This is examined in Paper 2, usually as "explain the difference" or "state which type".

Syntax errors

Logic errors

Telling them apart

The fastest test is what happens when you run the program. If it will not run and the translator reports an error, it is a syntax error. If it runs but gives the wrong result with no error message, it is a logic error. This is why logic errors are more dangerous: the program appears to work, so the bug can go unnoticed until it produces a wrong answer in use.

Try this

Q1. State what a syntax error is. [1 mark]

  • Cue. An error that breaks the rules (grammar) of the programming language, so the program will not run.

Q2. A program runs but always outputs a value that is too small. Which type of error is this? [1 mark]

  • Cue. A logic error (it runs but gives the wrong result).

Q3. State why logic errors are harder to find than syntax errors. [1 mark]

  • Cue. No error message is produced and the program does not stop, so you must work out that the output is wrong and track down the faulty logic yourself.

Exam-style practice questions

Practice questions written in the style of OCR exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

OCR 20214 marksExplain the difference between a syntax error and a logic error, giving an example of each.
Show worked answer →

Syntax error (up to 2): an error that breaks the grammar or rules of the programming language, so the program will not run (or will not translate). Example: a missing bracket, a misspelled keyword such as pirnt instead of print, or a missing endif.

Logic error (up to 2): an error where the program runs without crashing but produces the wrong result, because the logic of the algorithm is faulty. Example: using + instead of -, the wrong condition such as > instead of >=, or total = i instead of total = total + i.

Markers reward the breaks-the-rules-so-it-will-not-run distinction for syntax, the runs-but-wrong-result distinction for logic, and a matching example of each. A common error is giving a logic-error example for a syntax error.

OCR 20223 marksA program runs without any error messages but always outputs the wrong total. State which type of error this is, explain how you could find it, and state why this type is harder to find than the other.
Show worked answer →

Type (1): a logic error, because the program runs but gives the wrong result.

How to find it (1): trace the program by hand using a trace table, or add print statements (or use the debugger) to watch the variables and find where the value goes wrong.

Why harder to find (1): a logic error does not produce an error message and does not stop the program, so the computer cannot point to it; you must work out that the output is wrong and track down the faulty logic yourself, unlike a syntax error which the translator flags.

Markers reward identifying it as a logic error, a sensible method (tracing or debugging), and the reason that no error message is generated.

Related dot points

Sources & how we know this