Three Building Blocks, Infinite Possibilities

Every algorithm, no matter how complex, is built from just three basic building blocks. Whether it is a simple calculator, a video game, or the software that lands a spacecraft on Mars — it all comes down to these three programming constructs:

Understanding these three constructs is fundamental to computer science. Once you can identify and use them, you can design any algorithm and write any program.

Key Concept: The Three Constructs Sequence = instructions in order. Selection = making a choice (IF/ELSE). Iteration = repeating instructions (FOR/WHILE). Every program ever written uses some combination of these three constructs. Learn them well!

The Constructs in Everyday Life

You use these three constructs in daily life without even realising it:

Sequence in Real Life

When you make toast in the morning, you follow a sequence: get the bread, put it in the toaster, press the lever, wait, take the toast out, spread butter. The order matters — you cannot spread butter before toasting!

Selection in Real Life

When you get dressed, you make decisions: Is it raining? If yes, take an umbrella. If no, leave it at home. You are choosing a path based on a condition — that is selection.

Iteration in Real Life

When you practise penalty kicks, you repeat the same action over and over: place the ball, run up, kick, retrieve the ball, repeat. You might stop after 20 kicks (count-controlled) or keep going until you score 10 goals (condition-controlled). Both are iteration.

Think About It: Can you identify sequence, selection, and iteration in your morning routine? When do you do things in order? When do you make choices? What do you repeat?

The Three Constructs in Detail

1. Sequence

Instructions are executed one after another, in the order they are written — like following a recipe from top to bottom. This is the simplest construct. Every program uses sequence as its foundation.

Pseudocode — Sequence
INPUT radius
SET area TO 3.14 * radius * radius
OUTPUT area

In this example, the three instructions always run in exactly this order: first the input, then the calculation, then the output. Swapping the order would produce incorrect results or errors.

Why Computers Need EXACT Instructions If you tell a human “wait for the water to boil”, they know to keep checking until it boils. But a computer would just wait… forever! You’d need to say “keep checking if the temperature equals 100°C, and only stop when it does.”

2. Selection (Decisions)

The program makes a decision based on a condition. If the condition is true, one path is followed; if false, a different path is taken. This is like a fork in the road.

There are several types of selection:

IF...THEN...ELSE

Pseudocode — IF/ELSE
INPUT age
IF age >= 18 THEN
    OUTPUT "You can vote"
ELSE
    OUTPUT "You cannot vote yet"
ENDIF

IF...ELSEIF...ELSE (Multiple Conditions)

Pseudocode — Multiple Conditions
INPUT score
IF score >= 70 THEN
    OUTPUT "Distinction"
ELSEIF score >= 50 THEN
    OUTPUT "Pass"
ELSE
    OUTPUT "Fail"
ENDIF

The program checks each condition in order. As soon as one is true, it runs that block and skips the rest. If none are true, the ELSE block runs.

Nested Selection You can put an IF statement inside another IF statement. This is called nested selection. It allows you to check multiple layers of conditions, like: Is the user logged in? If yes, are they an admin?

3. Iteration (Loops)

A section of code is repeated either a set number of times or until a condition is met. This saves you from writing the same instructions over and over again.

There are three main types of iteration:

FOR Loop (Count-Controlled)

Repeats a set number of times. Use this when you know in advance how many times to loop.

Pseudocode — FOR Loop
FOR i = 1 TO 5
    OUTPUT "Hello " + i
ENDFOR

This outputs “Hello 1”, “Hello 2”, “Hello 3”, “Hello 4”, “Hello 5”.

WHILE Loop (Condition-Controlled — Pre-Check)

Checks the condition before each iteration. If the condition is false at the start, the loop body may never execute.

Pseudocode — WHILE Loop
SET count TO 1
WHILE count <= 10
    OUTPUT count
    SET count TO count + 1
ENDWHILE

REPEAT...UNTIL Loop (Condition-Controlled — Post-Check)

Checks the condition after each iteration. The loop body always executes at least once.

Pseudocode — REPEAT...UNTIL
REPEAT
    OUTPUT "Enter password:"
    INPUT password
UNTIL password == "secret123"
OUTPUT "Access granted"
WHILE vs. REPEAT...UNTIL The key difference is when the condition is checked. A WHILE loop checks before running the code (so it might run zero times). A REPEAT...UNTIL loop checks after running the code (so it always runs at least once). In the password example above, REPEAT...UNTIL is better because you need to ask for the password at least once before checking it.
Did You Know? We use iteration in our daily lives all the time! When traffic lights are red, you keep waiting UNTIL they turn green. When learning lines for a play, you repeat them over and over UNTIL you know them all. Every video game loop checks “has the player won?” repeatedly until you finish the level!

Combining the Three Constructs

Real programs combine all three constructs together. Here is an example that uses sequence, selection, and iteration:

Pseudocode — All Three Constructs
SET total TO 0                        // Sequence
SET count TO 0                        // Sequence

REPEAT                                // Iteration
    OUTPUT "Enter a mark (or -1 to finish):"
    INPUT mark                        // Sequence
    IF mark != -1 THEN                // Selection
        SET total TO total + mark     // Sequence
        SET count TO count + 1        // Sequence
    ENDIF
UNTIL mark == -1                      // Iteration condition

IF count > 0 THEN                     // Selection
    SET average TO total / count      // Sequence
    OUTPUT "Average mark: " + average
ELSE
    OUTPUT "No marks entered"
ENDIF

This algorithm repeatedly asks for marks (iteration), decides whether to add them (selection), and performs calculations in order (sequence). All three constructs working together.

Test Yourself

Click on each question to reveal the answer. Try to answer in your head first!

Q1: Name the three programming constructs and give one example of each.

Answer: Sequence — instructions run in order, e.g. calculating the area of a rectangle (length * width). Selection — a decision is made, e.g. IF age >= 17 THEN “can learn to drive.” Iteration — instructions repeat, e.g. a WHILE loop that keeps asking for a password until the correct one is entered.

Q2: What is the difference between a WHILE loop and a REPEAT...UNTIL loop?

Answer: A WHILE loop checks its condition before each iteration, so the loop body might never execute if the condition is false from the start. A REPEAT...UNTIL loop checks its condition after each iteration, so the loop body always executes at least once. Use REPEAT...UNTIL when you need the code to run at least once (e.g. asking for user input).

Q3: When would you use a FOR loop instead of a WHILE loop?

Answer: Use a FOR loop when you know in advance how many times you want to repeat (e.g. “print the times table for 1 to 12”). Use a WHILE loop when the number of repetitions depends on a condition that might change during the loop (e.g. “keep asking until the user types ‘quit’”).

Q4: What is nested selection? Give an example.

Answer: Nested selection is an IF statement placed inside another IF statement. For example:

Pseudocode
IF loggedIn == TRUE THEN
    IF role == "admin" THEN
        OUTPUT "Welcome, admin"
    ELSE
        OUTPUT "Welcome, user"
    ENDIF
ELSE
    OUTPUT "Please log in"
ENDIF

The inner IF only runs if the outer IF condition is true. This allows multi-layered decision making.

Q5: Identify the constructs used in this pseudocode: a program that asks for 5 numbers and outputs whether each is positive or negative.

Answer: This program uses all three constructs: Sequence — the INPUT and OUTPUT statements run in order within each iteration. Iteration — a FOR loop repeating 5 times. Selection — an IF/ELSE deciding whether each number is positive or negative.

Q6: Write pseudocode for a program that counts down from 10 to 1 and then outputs “Blast off!”

Answer:

Pseudocode
SET count TO 10
WHILE count >= 1
    OUTPUT count
    SET count TO count - 1
ENDWHILE
OUTPUT "Blast off!"

This uses sequence (OUTPUT then decrement) within iteration (WHILE loop). You could also use a FOR loop counting from 10 down to 1.

Q7: Why can’t every program be written using only sequence?

Answer: Sequence alone only allows instructions to run in a fixed order — it cannot make decisions or repeat actions. Without selection, a program cannot respond differently to different inputs. Without iteration, any repeated task would need to be written out individually, making programs enormously long and inflexible. The three constructs together give programs the flexibility to handle any situation.

Key Vocabulary

Make sure you understand and can define all of these terms.

TermDefinition
Sequence A programming construct where instructions are executed one after another in order.
Selection A programming construct where a decision is made based on a condition (e.g. IF...THEN...ELSE).
Iteration A programming construct where instructions are repeated, either a set number of times (FOR) or until a condition is met (WHILE/REPEAT...UNTIL).
Condition An expression that evaluates to TRUE or FALSE, used to control selection and iteration (e.g. age >= 18, password == “correct”).
Count-Controlled Loop A loop that repeats a specific number of times (FOR loop). The number of iterations is known before the loop starts.
Condition-Controlled Loop A loop that repeats until a condition is met (WHILE or REPEAT...UNTIL). The number of iterations is not known in advance.
Nested Selection An IF statement placed inside another IF statement, allowing multi-layered decision making.
Nested Iteration A loop placed inside another loop, often used for processing two-dimensional data (e.g. rows and columns).

Exam Tips: Programming Construct Questions

1. Identify All Three Constructs

A common exam question gives you a piece of pseudocode and asks you to identify the constructs used. Look for: statements running in order (sequence), IF/ELSE blocks (selection), and FOR/WHILE/REPEAT blocks (iteration). Make sure to give a specific example from the code for each one.

2. Choose the Right Loop Type

If the question says “repeat 10 times” → use a FOR loop. If it says “repeat until the user enters ‘quit’” → use a WHILE or REPEAT...UNTIL loop. If the action must happen at least once → prefer REPEAT...UNTIL.

3. Trace Through Carefully

When tracing code with loops and selection, go through one iteration at a time. Update each variable in your trace table before moving to the next step. Do not skip ahead or try to do multiple iterations in your head at once.

4. Watch for Off-by-One Errors

A very common mistake is getting the loop boundaries wrong. FOR i = 0 TO 4 runs 5 times (0, 1, 2, 3, 4), not 4. Always count carefully and check whether the boundary values are included.

Top Exam Tip: If a question asks you to “explain the purpose” of a construct in a program, do not just name it. Say what it does in context. For example: “The WHILE loop (iteration) repeatedly asks the user for a password until they enter the correct one, preventing unauthorised access.”

Past Paper Questions

Try these exam-style questions, then click to reveal the mark scheme answer.

Define the term 'iteration' in programming. [1] mark

Mark scheme:

Repeating a section of code / a loop that runs a block of code multiple times (1)

Explain the difference between definite and indefinite iteration. Give an example of each. [4] marks

Mark scheme:

  • Definite iteration repeats a fixed number of times / the number of repetitions is known before the loop starts (1)
  • Example: a for loop / for i in range(10) (1)
  • Indefinite iteration repeats until a condition is met / the number of repetitions is not known in advance (1)
  • Example: a while loop / while password != correct (1)
Explain the difference between selection and iteration. [2] marks

Mark scheme:

  • Selection is a decision / choosing which path to follow based on a condition (e.g. if/else) (1)
  • Iteration is repeating / looping a section of code (e.g. for, while) (1)

Think About It

The three programming constructs are the grammar of programming. Just as every English sentence uses nouns, verbs, and connectives, every program uses sequence, selection, and iteration.

Think about these connections:

Once you start seeing these patterns everywhere, you will find it much easier to design algorithms and write code. The three constructs are your toolkit — master them, and you can build anything.

Video Resources

Interactive Activities

  • Linked List Explorer — Add, remove and search a singly linked list with visual pointer animations
  • Stack Simulator — Push, pop and peek operations on a stack to understand LIFO behaviour

Interactive Games

  • Program Builder — 14 drag-and-drop challenges practising sequence, selection and iteration
  • Python Blocks — Visual block-based Python programming with Blockly

Further Reading