Topic 8 · Programming · 8.6

Selection Explained Simply

Selection lets a program make a decision. It checks a condition, then chooses which instructions should run.

Invitation

How does a program choose what to do?

Some programs cannot follow one straight path. They must check information and choose between different actions.

Selection is a programming construct where a condition is checked and the result decides which code runs.

Check a condition. Make a decision. Follow one route.
Figure 1
A simple decision
Is the score 50 or more?
↙     ↘
YES: Pass
NO: Try again
Big Idea

A condition produces TRUE or FALSE

A condition compares values using operators such as =, <, >, <= and >=.

The comparison produces one of two results: TRUE or FALSE. The program then follows the matching branch.

Selection does not guess. It follows the result of a condition.
Figure 2
Condition results
Age ≥ 16
TRUE or FALSE
Choose a route
FutureLogic Bridge

Selection is like a road junction

Imagine reaching a junction with a sign: “Is the bridge open?”

If the answer is yes, you take the bridge. If the answer is no, you take the diversion. The decision changes the route, but only one route is followed.

A condition is the road sign. Selection chooses the correct road.
Figure 3
The road-junction bridge
Condition
↙     ↘
TRUE route
FALSE route
Worked Example

Check whether a student has passed

The program checks the mark. If it is 50 or more, it displays Pass. Otherwise, it displays Not yet.

PseudocodeIF...ELSE
OUTPUT("Enter your mark")
INPUT Mark

IF Mark >= 50 THEN
    OUTPUT("Pass")
ELSE
    OUTPUT("Not yet")
ENDIF

Follow the condition

If Mark = 72, the condition 72 ≥ 50 is TRUE.

Output: Pass
Two Common Forms

IF statements and CASE statements

IFChecks a condition that is TRUE or FALSE.
ELSERuns when the IF condition is FALSE.
ELSEIFChecks another condition if the first was FALSE.
CASECompares one value against several possible choices.
Use IF for conditions. Use CASE when one value has several clear options.
Exam Tip

Read every comparison symbol carefully

A single symbol can change which branch runs. For example, > 50 does not include 50, but >= 50 does.

Strong answer: “Selection checks a condition and uses the result to decide which statements are executed.”

When tracing code, write down whether each condition is TRUE or FALSE before choosing the branch.

Common Mistake

“Both branches run.”

In a normal IF...ELSE statement, only one branch runs.

Incorrect: “The program outputs both Pass and Not yet.”
Correct: “The condition chooses one branch, so only one output is produced.”
Summary

The decision-making construct

ConditionA comparison is checked.
TRUE or FALSEThe condition has one of two results.
BranchThe result decides which route is followed.
IFUsed for conditional decisions.
CASEUseful for several fixed choices.
Only one routeUnselected branches are skipped.