Control Flow Lab
Sequence, selection and iteration are the three building blocks of every program. Learn the constructs, choose the right loop for the job, and trace a program line by line to predict exactly what it does.
Revise this, the fun way
Play it interactively, earn XP and build a streak, free.
Start revising freeWhat you'll cover
The building blocks of code 💻
Every program is built from a few basic **constructs**. Instructions run in **sequence**, **selection** chooses between paths, and **iteration** repeats steps. Add variables, subprograms and data structures and you can build almost anything. This module explores these constructs and how to **trace** what a program does.
The three constructs 🔑
Four ideas underpin every program:
Name the construct ❓
A program uses IF and ELSE to decide what to do next. Which construct is this?
- Selection
- Sequence
- Iteration
- Assignment
Match each construct to what it does 🔗
- Sequence
- Selection
- Iteration
- Subprogram
- Runs instructions one after another, in order
- Chooses a path using a condition, such as IF
- Repeats instructions using a loop
- A named block of code you can call and reuse
Two kinds of loop 🔁
Iteration uses loops, and there are two main kinds. Choosing the right one matters.
What is true of loops? ✅
Select the TWO statements that are true about loops.
- A FOR loop is count-controlled and repeats a set number of times
- A WHILE loop repeats while its condition is true
- A loop can only ever repeat exactly once
- Selection and iteration are the same construct
Read nested code with care ⚠️
Well-structured constructs have a **single entry point** and a **single exit point**, which makes them easier to follow and to test. When code is **nested** (a loop inside a loop, or an IF inside a loop), read it **line by line** and watch the **indentation** so you know which block each line belongs to. A **trace table**, with a column per variable, is the safest way to predict what nested code will do.
Complete the summary 🧩
Instructions that run in order use _____. Choosing between paths with IF uses _____. Repeating steps with a loop is _____. A count-controlled loop is a _____ loop, while a condition-controlled loop is a _____ loop.
Trace the loop 📊
An interactive activity.
Choose the right construct 🛠️
An interactive activity.
Predict the output 🎯
A program runs: x <- 8. IF x > 10 THEN OUTPUT High, ELSE IF x > 5 THEN OUTPUT Medium, ELSE OUTPUT Low. What is output?
- Medium, because 8 is not more than 10 but is more than 5
- High, because 8 is a fairly large number
- Low, because 8 is less than 10
- Both Medium and Low are output
Spot the true statements 🖍️
An interactive activity.
Selection and iteration ✍️
An interactive activity.