SLIDE 1 / 10
CSZone.co.uk
Click anywhere to advance · Arrow keys also work
AQA 7517 · Paper 1 · 4.1.2a

Selection
IF / ELSE / CASE

AQA A-Level Computer Science · Section 4.1 Fundamentals of Programming

WHAT YOU'LL LEARN
IF THEN ELSE ENDIF · ELSEIF · Nested selection · CASE ENDCASE
AQA SPEC LINK
4.1.2 — Selection as a programming construct
Selection

What is Selection?

Selection allows a program to choose between different paths of execution based on a Boolean condition. Only one branch executes.
AQA IF SYNTAX
IF condition THEN
  statements
ELSE
  statements
ENDIF
PYTHON EQUIVALENT
if condition:
  statements
else:
  statements
IF THEN ENDIF

Simple One-Way Selection

EXAMPLE — Age Check
age ← INT(USERINPUT)
IF age ≥ 18 THEN
  OUTPUT "You can vote"
ENDIF
OUTPUT "Age check complete"
Without ELSE, the block only runs when the condition is TRUE. The program always continues to OUTPUT "Age check complete".
ELSE / ELSEIF

Two-Way & Multi-Way Selection

GRADE CLASSIFIER — ELSEIF CHAIN
score ← INT(USERINPUT)
IF score ≥ 70 THEN
  OUTPUT "Grade A"
ELSEIF score ≥ 55 THEN
  OUTPUT "Grade B"
ELSEIF score ≥ 40 THEN
  OUTPUT "Grade C"
ELSE
  OUTPUT "Grade U"
ENDIF
⚠️ Conditions are evaluated in order — once a True branch is found, the rest are skipped. Order matters!
Nested Selection

Nested IF Statements

ENTRY SYSTEM EXAMPLE
IF hasTicket = True THEN
  IF age ≥ 18 THEN
    OUTPUT "Adult entry granted"
  ELSE
    OUTPUT "Child entry granted"
  ENDIF
ELSE
  OUTPUT "No ticket — entry denied"
ENDIF
Each nested IF must have its own ENDIF. Deeply nested code can often be simplified with Boolean operators (AND/OR).
CASE

CASE...ENDCASE — Multi-Way Selection

AQA MENU EXAMPLE
choice ← INT(USERINPUT)
CASE choice OF
  1: OUTPUT "New Game"
  2: OUTPUT "Load Game"
  3: OUTPUT "Settings"
  4: OUTPUT "Quit"
  OTHERWISE: OUTPUT "Invalid choice"
ENDCASE
CASE is cleaner than long ELSEIF chains when testing a single variable against multiple values. Python uses match/case (3.10+) or if/elif chains.
Flowcharts

Selection in Flowcharts

In flowcharts, selection is represented by a diamond shape (decision box) with:
· The condition written inside
· A YES branch and a NO branch exiting the diamond
Exam tip: always close branches back to the same point (merge point) after the selection, unless one branch returns/ends the program.
Boolean Simplification

Combining Conditions

VERBOSE — AVOID
IF age ≥ 18 THEN
  IF hasID = True THEN
    OUTPUT "Allowed"
  ENDIF
ENDIF
CLEANER — PREFERRED
IF age ≥ 18 AND hasID = True THEN
  OUTPUT "Allowed"
ENDIF
Same logic, fewer lines, easier to read
AQA Exam Style

Practice Question

AQA 7517 — Paper 1 Style
Write pseudocode that inputs a temperature and outputs one of: "Freezing" (<0), "Cold" (0–14), "Warm" (15–24), or "Hot" (25+).
[4 marks]
temp ← REAL(USERINPUT)
IF temp < 0 THEN
  OUTPUT "Freezing"
ELSEIF temp < 15 THEN
  OUTPUT "Cold"
ELSEIF temp < 25 THEN
  OUTPUT "Warm"
ELSE
  OUTPUT "Hot"
ENDIF
Summary

Key Points to Remember

IF THEN ENDIF — one-way selection (runs if condition True)
IF THEN ELSE ENDIF — two-way selection
ELSEIF — multi-way selection; conditions checked in order
CASE OF...ENDCASE — cleaner multi-way when testing one variable
Nested selection: each IF needs its own ENDIF; use AND/OR to simplify
🎉 Lesson complete — move to the quiz!