Selection and Iteration
Selection — IF statements
IF score >= 70 THEN
OUTPUT "Distinction"
ELSEIF score >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
Nested IF & logical operators
IF age >= 13 AND age <= 19 THEN
OUTPUT "Teenager"
ENDIF
Iteration — loops
Count-controlled (FOR) — known number of repeats:
FOR i ← 1 TO 10
OUTPUT i
NEXT i
Condition-controlled (WHILE) — repeats while true, may run zero times:
WHILE password != "1234"
password ← INPUT
ENDWHILE
REPEAT…UNTIL — runs at least once, checks at the end:
REPEAT
num ← INPUT
UNTIL num > 0
Choosing a loop
- Know how many times? → FOR
- Depends on a condition / input? → WHILE or REPEAT
Exam tip
A WHILE loop checks the condition first (could run 0 times); REPEAT checks last (always runs ≥1 time). State this difference for marks.