(a) Explain the difference between a syntax error and a logic error. [2]
(b) For each line below, state whether it contains a syntax error or a logic error. [2]
(i) IF score > 50 THN
(ii) A program meant to find the mean of 5 numbers uses mean ← total / 4
- (a) Syntax error: code breaks the rules / grammar of the programming language, so it cannot be translated / run(1)
- (a) Logic error: the program runs but produces an incorrect / unexpected result(1)
- (b)(i) Syntax error(1)
- (b)(ii) Logic error(1)
- Answer: (a) Syntax: breaks language rules, won't run; Logic: runs but gives wrong output (b)(i) syntax (ii) logic
- Examiner tip: Saying a logic error 'is a mistake in the code' is too vague. Say the program still runs but gives the wrong result.