AQA · GCSE · Computer Science

    Course version: 8525 · Version from Sept 2020

    Programming concepts: An example of nested selection would be:

    Nested selection means placing one selection structure (an IF, or IF–ELSE, or IF–ELSEIF) inside the branch of another, so the inner decision is only reached when the outer condition has already…

    Checked against the AQA 8525 specification (opens in a new tab) on .

    • Point 20 of 23

    Study notes

    From the checked teaching notes for this specification point.

    The idea

    Nested selection means placing one selection structure (an IF, or IF–ELSE, or IF–ELSEIF) inside the branch of another, so the inner decision is only reached when the outer condition has already been met. The outer condition is tested first; only if it is true does control enter its branch, where the inner condition is then tested. A correct example therefore shows two selection structures where the second sits physically inside the first, with its own condition and its own ENDIF. A sequence of two separate IF statements one after another is not nesting, because both are tested regardless of the first result. Likewise, a single IF with several conditions joined by AND or OR is one selection, not nested selection. When judging an option, trace the indentation and count the ENDIF keywords: nesting requires an inner IF that begins after the outer IF and closes before the outer ENDIF.

    What earns the marks

    • Identifies that nested selection places one selection structure inside the branch of another.
    • Recognises that the inner condition is only evaluated when the outer condition is true.
    • Distinguishes nesting from two sequential IF statements, which are both tested independently.
    • Distinguishes nesting from a single IF whose conditions are combined with AND or OR.
    • Checks that the inner IF has its own condition and its own ENDIF, closed before the outer ENDIF.
    • Uses indentation or structure to show which statements belong to the inner and outer branches.

    Common mistakes and how to put them right

    • Treating two consecutive IF statements as nested.

      Put it right by checking whether the second IF lies inside the first IF's branch, not merely after it.

    • Assuming a single IF with AND or OR is nested selection.

      Put it right by noting that combining conditions in one test is still one selection structure.

    • Forgetting the inner ENDIF or placing it after the outer ENDIF.

      Put it right by matching each IF with its own ENDIF in the correct order.

    Exam tips

    • Trace the code line by line, asking which condition is tested first and which is only reached when the outer test is true.
    • Count the IF and ENDIF keywords; nesting needs an inner IF opened after the outer IF and closed before the outer ENDIF.
    • Eliminate options that show sequential or combined-condition tests before choosing the nested example.

    Try the lesson

    The start of the Programming concepts: An example of nested selection would be: lesson, made from checked teaching notes for this specification point.

    Have a go first

    Which of these code fragments shows selection placed inside another selection?

    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 Programming concepts: An example of nested selection would be:

    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