Cambridge IGCSE Computer Science (0478) · lesson 30 of 35 · 25 min
The Three Programming Constructs
Every algorithm can be expressed using just three control structures:
- Sequence: Instructions executed one after another in order.
- Selection: Choosing which instructions to execute based on a condition (IF/ELSE, CASE).
- Iteration: Repeating instructions (FOR, WHILE, REPEAT).
Selection — IF and CASE
Grade classifier using nested IF
INPUT score
IF score >= 70 THEN
OUTPUT “Distinction”
ELSE IF score >= 50 THEN
OUTPUT “Merit”
ELSE IF score >= 40 THEN
OUTPUT “Pass”
ELSE
OUTPUT “Fail”
ENDIF
Iteration — Choosing the Right Loop
Sum of numbers until user enters 0
total ← 0
REPEAT
INPUT num
total ← total + num
UNTIL num = 0
OUTPUT total
Which loop is guaranteed to execute its body at least once?
- FOR
- WHILE
- REPEAT…UNTIL
- None of them
Answer: REPEAT…UNTIL
REPEAT…UNTIL checks the condition after the body, so it always executes at least once.
You need to repeat an action exactly 5 times. Which loop is most appropriate?
- WHILE
- REPEAT…UNTIL
- FOR
- IF
Answer: FOR
FOR loops are ideal when the number of iterations is known in advance.
What are the three fundamental programming constructs?
- Input, process, output
- Sequence, selection, iteration
- Variables, functions, loops
- Compile, run, debug
Answer: Sequence, selection, iteration
All algorithms can be built from sequence, selection, and iteration.
Previous lesson: Variables, constants, and data types
Back to Cambridge IGCSE Computer Science (0478)
Next lesson: Arrays and string handling