Study Notes
Overview

Welcome to Programming Constructs! This topic is the beating heart of Computer Science. Whether you are building a simple calculator or the software that runs a Mars rover, every single program is built from just three fundamental structural components: Sequence, Selection, and Iteration.
Understanding these constructs is crucial because examiners don't just want you to memorise definitions; they want to see you apply them to solve problems. This topic connects deeply to algorithms, data representation, and computational thinking. Typical exam questions will ask you to write code snippets, trace algorithms using trace tables, or identify logic errors where these constructs have been used incorrectly.
Key Concepts
Concept 1: The Three Core Constructs
Every program relies on these three building blocks. Examiners expect you to identify them and use them appropriately.

- Sequence: This is the default behaviour of a program. Instructions are executed one after another, in the exact order they are written, from top to bottom. If you write
print("A")beforeprint("B"), "A" will always appear first. - Selection: This allows a program to make decisions. It uses conditions (which evaluate to True or False) to determine which path of code to execute. We typically use
if,elif, andelsestatements. Think of it like a fork in the road. - Iteration: This is looping—repeating a block of code. There are two main types you must master:
- Count-controlled iteration (
forloops): Used when you know exactly how many times the code needs to repeat. - Condition-controlled iteration (
whileloops): Used when you don't know how many times the code needs to repeat; it loops until a condition becomes False.
- Count-controlled iteration (
Concept 2: Variables and Constants
Programs need to store data while they run.
- A variable is a named memory location whose value can change while the program is running (e.g.,
playerScore = 10). - A constant is a named memory location whose value cannot change while the program is running (e.g.,
PI = 3.14159).
Why use constants? They make code more readable and easier to maintain. If a fixed value changes in the future (like a VAT rate), you only have to update it in one place at the top of your code, rather than hunting through hundreds of lines.
Concept 3: Subprograms (Procedures vs Functions)
As programs get larger, they become harder to read and debug. We solve this by breaking them down into smaller, reusable blocks called subprograms.

There is a critical distinction examiners test every year:
- Procedures: Perform a specific task but do not return a value to the main program. (e.g., clearing the screen).
- Functions: Perform a specific task and return a value to the main program using a
returnstatement. (e.g., calculating an area and returning the result).
Both can accept parameters—values passed into the subprogram to give it the data it needs to work.
Concept 4: Variable Scope (Global vs Local)
Where you declare a variable determines where it can be used.

- Global Variables: Declared outside any subprogram. They can be accessed and modified from anywhere in the entire program.
- Local Variables: Declared inside a specific subprogram. They can only be accessed within that subprogram and are destroyed when the subprogram finishes running.
Examiner Tip: Always prefer local variables! They keep subprograms self-contained and prevent accidental changes to data from other parts of the program.
Podcast Episode
Listen to our 10-minute revision podcast covering all the core concepts, common exam mistakes, and a quick-fire recall quiz!
Visual Resources
3 diagrams and illustrations
Interactive Diagrams
2 interactive diagrams to visualise key concepts
Conceptual Flow Outline
A flowchart demonstrating the Selection construct using a condition.
Conceptual Flow Outline
A flowchart demonstrating Condition-Controlled Iteration (a while loop).
Worked Examples
3 detailed examples with solutions and examiner commentary
Practice Questions
Test your understanding — click to reveal model answers
Identify the programming construct used in the following code: for i in range(10): print(i)
Hint: Look at the keyword 'for'. Does it make a decision, or does it repeat?
State two advantages of using subprograms in a large software project.
Hint: Think about what happens if you find a bug, or if multiple people are working on the code.
A student has written a program with a variable total declared inside a function called calculate(). They try to print(total) in the main program, but get an error. Explain why.
Hint: Think about the scope of the variable `total`.
Write a function called is_even that takes an integer as a parameter and returns True if the number is even, and False if it is odd.
Hint: You will need to use the modulo operator (MOD or %) to check for a remainder when divided by 2.
Explain the difference between count-controlled iteration and condition-controlled iteration, giving an example of when you would use each.
Hint: Compare 'for' loops with 'while' loops based on what you know *before* the loop starts.