OCR · GCSE · Computer Science

    Course version: J277 · Version from Sept 2022

    Designing, creating and refining algorithms: Identify common errors

    Identifying common errors means reading an algorithm and finding where it will not do what is intended.

    Checked against the OCR J277 specification on .

    • Point 4 of 5
    • 4 key terms

    Study notes

    From the checked teaching notes for this specification point.

    The idea

    Identifying common errors means reading an algorithm and finding where it will not do what is intended. You check each line against the purpose: syntax errors break the rules of the language, such as a missing bracket or a misspelled keyword; logic errors run but give wrong output, such as using < instead of > or adding instead of subtracting; runtime errors stop the program, such as dividing by zero or reading past the end of an array. A useful method is to trace a small input by hand, compare the result with the expected result, then fix the first error and retest. In an exam you may be shown pseudocode or a program and asked to state the error and the correction, so name the line and explain the effect.

    What earns the marks

    • Distinguishes syntax, logic and runtime errors and gives a correct example of each in pseudocode or a high-level language.
    • Locates an error by tracing a short input through the algorithm and comparing the actual output with the expected output.
    • Explains the effect of an error, such as an infinite loop, an incorrect total, or a program crash, rather than only naming the line.
    • States a valid correction, for example changing a comparison operator, swapping two statements, or adding a missing initialisation.
    • Checks boundary cases such as an empty list, a zero value, or the first and last items, where errors often appear.
    • Uses test data that includes normal, boundary and erroneous values to expose different faults.

    Common mistakes and how to put them right

    • Confusing a logic error with a syntax error.

      Put it right: A syntax error prevents the program running at all, while a logic error runs but produces wrong output.

    • Assuming an algorithm is correct because it works for one input.

      Put it right: Test several inputs, including boundary values, before deciding there is no error.

    • Changing many lines at once when correcting an algorithm.

      Put it right: Fix one error, retest, then continue so you can see which change solved the problem.

    Exam tips

    • Quote the line or statement that contains the error, then state the correction separately so both parts are clear.
    • Use the words syntax, logic and runtime accurately; do not use them as synonyms.
    • When asked to identify an error, describe what the code does now and what it should do instead.

    Try the lesson

    The start of the Designing, creating and refining algorithms: Identify common errors lesson, made from checked teaching notes for this specification point.

    Have a go first

    A program should output the numbers 1 to 5, but it outputs 1 to 4. Which type of error is this?

    Listen

    Identifying common errors means reading an algorithm and finding where it will not do what is intended. You check each line against the purpose: syntax errors break the rules of the language, such as a missing bracket or a misspelled keyword; logic errors run but give wrong output, such as using or adding instead of subtracting; runtime errors stop the program, such as dividing by zero or reading past the end of an array. A useful method is to trace a small input by hand, compare the result with the expected result, then fix the first error and retest. In an exam you may be shown pseudocode or a program and asked to state the error and the correction, so name the line and explain the effect. A strong answer earns marks for these points. Distinguishes syntax, logic and runtime errors and gives a correct example of each in pseudocode or a high-level language. Locates an error by tracing a short input through the algorithm and comparing the actual output with the expected output. Explains the effect of an error, such as an infinite loop, an incorrect total, or a program crash, rather than only naming the line. States a valid correction, for example changing a comparison operator, swapping two statements, or adding a missing initialisation. A common slip: Confusing a logic error with a syntax error. Instead, a syntax error prevents the program running at all, while a logic error runs but produces wrong output. Exam tip: Quote the line or statement that contains the error, then state the correction separately so both parts are clear.

    Key words

    Say what each word means before you turn the card.

    Syntax error

    Try answering aloud or in your head before turning the card.

    Logic error

    Try answering aloud or in your head before turning the card.

    Runtime error

    Try answering aloud or in your head before turning the card.

    Trace

    Try answering aloud or in your head before turning the card.

    See every definition
    Syntax error
    An error that breaks the rules of the language, such as a missing bracket or a misspelled keyword, and prevents the program running at all.
    Logic error
    An error where the program runs but gives wrong output, such as using < instead of > or adding instead of subtracting.
    Runtime error
    An error that stops the program, such as dividing by zero or reading past the end of an array.
    Trace
    A useful method of following a small input by hand and comparing the result with the expected result to find an error.

    There is more to this lesson

    The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.

    Carry on with the full lesson

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge

    Test your understanding of Designing, creating and refining algorithms: Identify common errors

    Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.

    Take topic quiz

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge