PAPER 2 • 2.2.1 Programming Fundamentals • SELECTION

Do Now!

Selection lets a program choose a path. We use if when checking conditions and switch when choosing between named options.

Selection structures diagram A visual comparing if then else and switch selection structures with branches and outputs. IF / ELSEIF / ELSE check a condition true path false path SWITCH / CASE test one value case 1 case 2 default

Today's Big Idea

Both structures are used for selection, but they shine in different situations. if is best for testing conditions like greater than or equal to, while switch is useful when one variable can match several fixed values.

if Checks whether a condition is true or false.
elseif Adds another condition if the earlier one was false.
switch Compares one value against several possible cases.

Activity 1: Match the Key Terms

Drag each term into the correct definition.

IF
ELSEIF
ELSE
SWITCH
CASE
DEFAULT
Term Definition
Starts a decision by testing a condition.
Checks another condition only if the earlier test was false.
Runs when none of the earlier conditions were true.
Selects between several fixed options using one value.
A possible option inside a switch statement.
The path used if no case matches.

Activity 2: Which Structure Fits Best?

Sort each prompt into the structure that makes the most sense.

Checking whether a mark is at least 50.
Choosing between Hot, Warm and Cold using temperature ranges.
Testing whether a password is correct.
Deciding whether someone gets an adult or child ticket.
Picking a menu option from "1", "2" or "3".
Choosing a lesson based on day = "Mon" or "Tue".
Reacting to a single grade code like "A", "B" or "C".
Handling a simple game menu with named choices.

Use IF / ELSEIF / ELSE

Use SWITCH / CASE / DEFAULT

Activity 3: Predict the Output

Use the code to decide what each program will print.

Predict 1

age = 14
if age >= 16 then
    print("Adult ticket")
else
    print("Child ticket")
endif

Predict 2

score = 62
if score >= 70 then
    print("Distinction")
elseif score >= 50 then
    print("Pass")
else
    print("Retry")
endif

Predict 3

day = "Tue"
switch day :
    case "Mon":
        print("PE")
    case "Tue":
        print("Music")
    default:
        print("Normal day")
endswitch

Activity 4: Explain the Choice

Read the task below and explain which part should use a switch statement and which part should use an if statement.

Task Scenario

A game checks whether a password is correct, then shows a menu where the player can choose "1" Start, "2" Load or "3" Quit.

Think about what is being tested. Passwords are usually checked with a true or false condition, so if is a good fit. A menu choice compares one variable with several fixed values, so switch is usually clearer.

Download PDF Evidence

Create a record of your starter activity responses.