In simple terms
A friendly intro before the formal notes — no formulas yet.
The Programmer's Recipe Book
Programming is like writing a recipe for a computer to follow. To do this, you need ingredients (variables), a set of instructions (control structures), and some pre-prepared techniques (methods).
Imagine you're baking a cake. Your variables are the ingredients listed with specific amounts, like or . The control structures are the steps in the recipe: 'IF the mixture is too dry, THEN add milk' (selection), or 'WHILE stirring, slowly add the sugar' (iteration). A method is like a pre-existing skill you use, such as 'cream the butter and sugar', which is a mini-recipe you can use in many different cakes without writing out the steps every time.
- 1
Declare a variable to act as a named container for a piece of data, like .
- 2
Use selection statements like if-else to make the program choose a path, e.g., check if .
- 3
Employ iteration (loops) like for or while to repeat a block of code, such as printing numbers from 1 to 10.
- 4
Encapsulate a specific task into a method, like calculateAverage(num1, num2), to make code modular and reusable.
Explore the concept
Use the live diagram and synced steps — play it or tap a step card to walk through.
Full topic notes
Formal explanation with the rigour you need for the exam.
Variables, Constants, and Data Types
At its heart, a computer program manipulates data. To do this, we need a way to store the data in the computer's memory. A variable is a named location in memory that holds a value. Think of it as a labelled box where you can put something. The contents of the box (the value) can be changed later on. For example, a variable called playerScore might start at 0 and increase as the game progresses.
A constant is similar, but its value cannot be changed once it has been set. This is useful for values that should never change, like the value of Pi or the number of days in a week. Using constants makes code easier to read and maintain. All variables and constants have a data type, which tells the computer what kind of data it is storing, such as an integer (integer), a number with a decimal point (float or real), a sequence of characters (string), or a true/false value (boolean).
Variable: A named storage location whose value can change.
Constant: A named storage location whose value cannot change after initialization.
Declaration: Creating a variable (e.g., variable score).
Initialization: Assigning an initial value to a variable (e.g., ).
Common Data Types: integer, real/float, string, boolean.
Operators
Operators are special symbols that perform operations on variables and values. We can group them into three main categories:
Arithmetic Operators: Used for mathematical calculations. Examples: + (addition), - (subtraction), * (multiplication), / (division), MOD (modulo, remainder), DIV (integer division).
Relational Operators: Used for comparison. They evaluate to a boolean (true or false). Examples: (equal to), (not equal to), (less than), (greater than), (less than or equal to), (greater than or equal to).
Logical Operators: Used to combine or modify boolean expressions. Examples: AND (both conditions must be true), OR (at least one condition must be true), NOT (inverts the boolean value).
Control Structures
Control structures dictate the order in which the statements in a program are executed. Without them, a program would just be a simple, linear sequence of instructions. The three fundamental structures are sequence, selection, and iteration.
Sequence is the default. Code is executed line by line, from top to bottom.
Selection allows the program to make a choice. The IF...THEN...ELSE construct is the most common form. The program evaluates a condition; if it's true, one block of code is executed. If it's false, another block (the ELSE part) is executed. You can also have nested IF statements for more complex decisions.
Iteration (or looping) allows a block of code to be executed multiple times. A FOR loop is used when you know how many times you want to loop (a counted loop). A WHILE loop is used when you want to keep looping as long as a certain condition remains true (a condition-controlled loop).
In exams, you must use the IB-approved pseudocode standard. Pay close attention to keywords like loop...endloop, if...then...else...endif, and how variables are declared. Clear indentation is not just for readability; it helps you structure your logic correctly and can make it easier for examiners to award marks for correct structure, even if there's a small error elsewhere.
Methods (Sub-routines)
As programs grow larger, it becomes essential to organise the code. A method (also called a sub-routine, function, or procedure) is a self-contained block of code that performs a single, well-defined task. For example, you could have a method to calculate a user's BMI, another to validate their password, and a third to display a menu. Methods can accept data through parameters and can optionally return a value back to the part of the code that called them.
Modularity: Breaking a complex problem into smaller, simpler pieces.
Reusability: A method can be called multiple times from different places in the program, avoiding code duplication.
Abstraction: Hiding the complex details of a task behind a simple method call. You don't need to know how a method works, only what it does.
Parameters: Variables used in a method to receive input values.
Return Value: A value that a method can send back to the caller.
Worked examples
See the formulas applied — reveal one step at a time, like the exam.
A program needs to calculate the total cost of items in a shopping basket. An item costs £4.50. There is a shipping fee of £3.00. The program should calculate the total cost for 5 items. Write the pseudocode for this calculation.
- 1
// Declare constants and variables constant ITEM_PRICE = 4.50 constant SHIPPING_FEE = 3.00 variable quantity = 5 variable subTotal variable totalCost
Write a pseudocode algorithm that asks a user for their age. If the age is 18 or over, it should output "Access granted". Otherwise, it should output "Access denied".
- 1
variable age
How it all connects
The big idea sits in the middle — tap a linked idea to explore the link.
Tap a linked idea to see how it connects back to the main topic — that connection is what examiners reward.
Glossary
Try to recall each definition before you reveal it.
Quick check
Answer in your head first — then tap to check. No pressure.
Revision flashcards
Flip the card. Test yourself before the exam.
What is a variable?
A named memory location that stores a value which can change during the program's execution. For example, .
Key takeaways
Review these before you close the topic — retrieval beats re-reading.
- ✓
Variable: A named storage location whose value can change.
- ✓
Constant: A named storage location whose value cannot change after initialization.
- ✓
Declaration: Creating a variable (e.g., variable score).
- ✓
Initialization: Assigning an initial value to a variable (e.g., ).
- ✓
Common Data Types: integer, real/float, string, boolean.
Practice — then mark it
The whole point: a real Cambridge question, marked mark-by-mark.
Practice Problems
Practice Problems
Extra simulations & links
PhET, GeoGebra and other curated tools — open in a new tab.
Frequently asked
Checkpoint
One marked question is worth ten re-reads — close the loop before you move on.
Reading it isn’t knowing it — prove it.
Before you move on: do Practice Problems on paper, snap a photo, and get examiner-style feedback on exactly where you win and lose marks.