Predict 1
age = 14
if age >= 16 then
print("Adult ticket")
else
print("Child ticket")
endif
PAPER 2 • 2.2.1 Programming Fundamentals • SELECTION
Selection lets a program choose a path. We use if when checking conditions and switch when choosing between named options.
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.
Drag each term into the correct definition.
| 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. |
Sort each prompt into the structure that makes the most sense.
Use the code to decide what each program will print.
age = 14
if age >= 16 then
print("Adult ticket")
else
print("Child ticket")
endif
score = 62
if score >= 70 then
print("Distinction")
elseif score >= 50 then
print("Pass")
else
print("Retry")
endif
day = "Tue"
switch day :
case "Mon":
print("PE")
case "Tue":
print("Music")
default:
print("Normal day")
endswitch
Read the task below and explain which part should use a switch statement and which part should use an if statement.
A game checks whether a password is correct, then shows a menu where the player can choose "1" Start, "2" Load or "3" Quit.
if is a good fit. A menu choice compares one variable with several fixed values, so switch is usually clearer.
Create a record of your starter activity responses.