Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Designing, creating and refining algorithms

Identify common errors

All topicsPractise exam questions
Knowledge organiser

Designing, creating and refining algorithms

2.1.2f

Identify syntax/logic errors in code and suggest fixes

What you need to know

When writing or reading algorithms, you need to be able to identify two types of error: syntax errors and logic errors. Syntax errors break the rules of the programming language and stop the program from running. Logic errors allow the program to run but produce incorrect or unexpected results. Being able to spot and fix both is a key programming skill.

Key points

  • Definition:Syntax error: breaks the rules/grammar of the programming language; prevents the program from running/executing.
  • Common syntax errors: misspelling keywords (printt), missing brackets, missing quotation marks, incorrect indentation, using =< instead of <=.
  • Definition:Logic error: the program runs but produces incorrect/unexpected results/output.
  • Common logic errors: using the wrong variable (num1 + num1 instead of num1 + num2), incomplete conditions, wrong loop bounds, wrong operator.
  • Syntax errors are flagged by the IDE or interpreter and are easier to fix.
  • Logic errors are harder to find because the program still runs; testing helps identify them.
  • Exam Tip:A DEFINITION must be general. 'Missing bracket' is an EXAMPLE of a syntax error, not a definition. The definition is 'breaks the rules/grammar of the language'.
  • Exam Tip:'Error in the syntax' or 'error in the logic' are NOT acceptable definitions (circular). 'Does not work' is too vague.
  • You should be able to suggest fixes for both types of error in exam questions. Write the corrected LINE of code.

Code examples

Syntax error vs Logic error
python
# SYNTAX ERROR - missing closing bracket
# print("Hello World"

# LOGIC ERROR - wrong formula
distance = 100
time = 20
speed = time / distance  # Should be distance / time
print(speed)  # Outputs 0.2 instead of 5.0