Selection is how a program makes decisions — it runs different blocks of code depending on whether a condition is true or false. At KS3, selection is taught alongside sequence and iteration as one of the three core programming constructs. Without it, every program would follow a single fixed path regardless of the user's input or the data it receives.

What is selection in KS3 computing?

Selection means choosing which section of code to execute based on a condition. The DfE national curriculum for computing states that KS3 students must understand programs that use "sequence, selection, and iteration" (gov.uk/government/publications/national-curriculum-in-england-computing-programmes-of-study). Selection is what makes programs responsive — a quiz app that checks whether an answer is correct, a game that detects whether a player has won, and a login system that checks a password are all using selection.

If statements: the simplest form of selection

An if statement runs a block of code only when a condition is True. If the condition is False, the block is skipped and the program continues after it.

If statement in pseudocode

IF score >= 50 THEN
    OUTPUT "Pass"
ENDIF

If statement in Python

score = int(input("Enter your score: "))
if score >= 50:
    print("Pass")

The indented block (four spaces in Python) only runs when score >= 50 is true.

If/else: handling two outcomes

An if/else statement handles two possible outcomes: one block runs when the condition is True, the other runs when it is False.

If/else in pseudocode

IF score >= 50 THEN
    OUTPUT "Pass"
ELSE
    OUTPUT "Not yet — keep practising"
ENDIF

If/else in Python

score = int(input("Enter your score: "))
if score >= 50:
    print("Pass")
else:
    print("Not yet — keep practising")

Worked example: grade classifier

score = int(input("Enter your percentage score: "))
if score >= 70:
    print("Grade A")
else:
    print("Grade B or below")

This handles exactly two cases. For more than two outcomes, use elif.

If/elif/else: multiple branches

elif (short for "else if") lets you chain together several conditions so only the first matching branch runs.

Worked example: traffic light

light = input("Enter light colour (red/amber/green): ")
if light == "green":
    print("Go")
elif light == "amber":
    print("Prepare to stop")
elif light == "red":
    print("Stop")
else:
    print("Unknown light colour")

Python checks each condition in order. As soon as one is True, it runs that block and skips the rest. The else at the end catches anything that did not match.

Worked example: grade classifier with four bands

score = int(input("Enter your score out of 100: "))
if score >= 70:
    grade = "A"
elif score >= 60:
    grade = "B"
elif score >= 50:
    grade = "C"
else:
    grade = "U"
print("Your grade is", grade)

BBC Bitesize (bbc.co.uk/bitesize/subjects/zvc9q6f) has interactive selection exercises for Year 7, 8, and 9 students that let you trace through if/elif/else chains step by step.

Nested if statements

A nested if statement is an if statement placed inside another if statement. This lets you test a second condition only after a first condition is confirmed true.

age = int(input("Enter your age: "))
has_ticket = input("Do you have a ticket? (yes/no): ")

if age >= 12:
    if has_ticket == "yes":
        print("You may enter")
    else:
        print("You need a ticket")
else:
    print("Sorry, this event is for age 12 and over")

Nesting should be used sparingly. More than two levels of nesting makes code hard to read; elif chains are often clearer.

Boolean conditions and comparison operators

Every condition in a selection statement evaluates to either True or False — this is a Boolean value. Python uses comparison operators to build these conditions.

Comparison operators

Operator Meaning Example Result
== Equal to 5 == 5 True
!= Not equal to 5 != 3 True
< Less than 3 < 10 True
> Greater than 10 > 3 True
<= Less than or equal to 5 <= 5 True
>= Greater than or equal to 6 >= 7 False

Combining conditions with and, or, not

You can combine multiple conditions using the logical operators and, or, and not:

age = 15
has_id = True

if age >= 18 and has_id:
    print("Entry allowed")
else:
    print("Entry refused")

# 'or' — at least one condition must be True
if age < 13 or age > 17:
    print("Not a teenager")

# 'not' — reverses the Boolean value
if not has_id:
    print("Please show ID")

Common mistakes with selection at KS3

1. Using = instead of ==

= is the assignment operator (it stores a value). == is the comparison operator (it checks equality). Writing if score = 50: is a syntax error in Python.

# Wrong
if score = 50:
    print("Equal")

# Correct
if score == 50:
    print("Equal")

2. Forgetting indentation

Python uses indentation to define which code belongs inside an if block. Every line inside the block must be indented by four spaces. Inconsistent indentation causes IndentationError.

3. Checking a string with the wrong case

"Yes" == "yes" is False in Python. Use .lower() or .upper() to standardise user input before comparing:

answer = input("Ready? ").lower()
if answer == "yes":
    print("Let's go!")

4. Ordering elif branches incorrectly

With numeric ranges, always put the most restrictive condition first. If you put score >= 50 before score >= 70, then a score of 75 would match the first branch and never reach the grade-A branch.

Frequently asked questions

What is selection in KS3 computing?

Selection is the programming construct that allows a program to follow different paths depending on whether a condition is true or false. It is implemented using if, if/else, and if/elif/else statements. Selection is one of the three core constructs in the KS3 computing curriculum, alongside sequence and iteration.

What is the difference between if, elif, and else in Python?

if checks the first condition. elif (else if) checks an additional condition only if all previous conditions were false. else runs when none of the preceding conditions were true. Together they form a chain where exactly one branch runs.

Why does Python use == instead of = for comparison?

The single equals sign = is the assignment operator — it stores a value in a variable (e.g. score = 10). The double equals sign == is the comparison operator — it checks whether two values are equal and returns True or False. Mixing them up is one of the most common beginner mistakes.

What is a Boolean in KS3 computing?

A Boolean is a data type that can only hold one of two values: True or False. Every condition in a selection statement produces a Boolean result. The name comes from the mathematician George Boole, who developed the algebra of logic that underpins modern computing.

When should you use a nested if statement?

Use a nested if statement when a second condition only makes sense to check after a first condition has already been confirmed as true. However, if you find yourself nesting more than two levels deep, consider rewriting with elif chains or combining conditions with and — it will be easier to read and debug.


For Socratic computing tutoring at KS3 — see aitutors.me.