Skip to content
VirtusAcademy

Selection (IF Statements)

FoundationHigherAQA

Learn Selection (IF Statements) for GCSE Computer Science with this free worksheet and full mark scheme — Foundation and Higher exam-style questions with worked answers for AQA GCSE Computer Science (8525). Selection uses IF statements so a program can make decisions and run different code.

Free downloads

These worksheets and mark schemes are original, written for Virtus Academy and checked against the current AQA specification. Every worksheet comes with a full mark scheme.

Topic overview

Selection means choosing which code to run based on a condition. It is implemented with an IF statement.

The basic form is IF condition THEN statements ENDIF. Adding ELSE provides an alternative when the condition is False. ELSE IF allows several conditions to be tested in turn, and the first one that is True has its block executed — the rest are skipped entirely.

That last point is what makes ordering matter. If a grade boundary check tests for 40 before 70, every mark above 70 would be caught by the first condition and never reach the second. Testing the most specific or highest condition first avoids this.

Revision notes

The forms of IF

IF condition THEN statements ENDIF runs the statements only when the condition is True.

IF ... THEN ... ELSE ... ENDIF provides an alternative. ELSE IF adds further conditions tested in turn.

Order matters

With ELSE IF, the first True condition runs and the rest are skipped.

So for grade boundaries, test the highest first: IF mark ≥ 70 THEN 'A' ELSE IF mark ≥ 40 THEN 'C'. Reversing this would give 'C' to every mark above 40, including 90.

Nested versus chained

ELSE IF chains test alternatives at the same level, and only one branch runs.

Nesting an IF inside another tests a second condition only when the first was True. Choose the structure that matches the logic required.

Key points

  • Selection chooses which code to run.
  • IF runs code when a condition is True.
  • ELSE provides an alternative.
  • ELSE IF tests further conditions in turn.
  • The first True condition runs, others are skipped.
  • Test the highest boundary first.

Worked examples

Example 1

Write pseudocode that outputs 'Pass' if mark is 40 or more and 'Fail' otherwise. [3 marks]

Working

IF mark ≥ 40 THENwrite the condition
OUTPUT 'Pass' ELSE OUTPUT 'Fail'give both branches
ENDIFclose the structure

Example 2

Explain why grade boundaries should be tested from highest to lowest in an ELSE IF chain. [2 marks]

Working

The first condition that is True has its block run and the rest are skippedstate how ELSE IF works
so testing 40 before 70 would give the lower grade to every mark above 40, including 90explain the consequence

Example 3

State what happens when no condition in an IF ELSE IF chain is True and there is no ELSE. [1 mark]

Working

No statements are executed and the program continues after the ENDIFstate the outcome

Common mistakes

  • Forgetting the ENDIF.

    Every IF must be closed.

  • Testing boundaries in the wrong order.

    Test the highest first, or lower conditions capture everything.

  • Using = for comparison inconsistently.

    In pseudocode = tests equality; ← assigns.

  • Assuming an ELSE always runs.

    It runs only when every preceding condition was False.

Exam tips

  • Close every IF with ENDIF.
  • Order ELSE IF conditions from most to least specific.
  • Indent the statements inside each branch.
  • Check what happens when no condition is True.

Key terms

Selection
Choosing which code to run based on a condition.
IF statement
The structure implementing selection.
ELSE
The branch run when the condition is False.
ELSE IF
A further condition tested when earlier ones were False.

Written and reviewed against the current AQA specification. Spotted an error? Let us know.