In simple terms
A friendly intro before the formal notes — no formulas yet.
The Programmer's Recipe Book
Writing a program is like writing a recipe for a computer to follow. You need to list your ingredients (variables), provide step-by-step instructions (sequence), include decision points (selection), and specify repetitive tasks (iteration).
Imagine you're baking a cake. Your variables are the ingredients: flourAmount, numberOfEggs, sugarGrams. A constant might be the , which doesn't change. The recipe itself is a sequence of instructions. A selection statement is like, 'IF the batter is too dry, THEN add a splash of milk'. An iteration is a loop, like 'WHISK for 3 minutes'. A sub-routine is like a mini-recipe for 'making the frosting', which you might use for many different cakes.
- 1
First, declare your variables and constants. This is like listing all the ingredients and equipment you'll need before you start cooking.
- 2
Next, write the basic sequence of instructions. These are the simple, step-by-step commands the computer executes in order, like 'mix flour and sugar'.
- 3
Then, add control structures to manage the flow. Use 'IF' statements for decisions and 'FOR' or 'WHILE' loops for repetitive tasks, making your program dynamic.
- 4
Finally, organise your code into sub-routines (methods). Group related instructions into named blocks that you can call whenever needed, keeping your main program clean and readable.
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 program manipulates data. To do this, we need places to store that data. A variable is a named location in the computer's memory where we can store a value. The key feature of a variable is that its value can change as the program runs. A constant is similar, but its value is fixed when the program starts and cannot be changed. Using constants for values like the rate of VAT or the value of Pi makes code more readable and easier to maintain.
Every variable or constant has a data type, which tells the computer what kind of data it holds. This is crucial because it determines how the data is stored and what operations can be performed on it. You can't, for example, mathematically multiply two strings of text.
Integer: Whole numbers, positive or negative (e.g., -5, 0, 42).
Real / Float: Numbers with a fractional part (e.g., 3.14, -0.01, 99.9).
String: A sequence of characters, enclosed in quotes (e.g., "Hello World", "IB CS").
Char: A single character (e.g., 'A', '!').
Boolean: Represents logical values, can only be true or false.
Operators
Operators are special symbols that perform operations on variables and values (operands). They are the verbs of programming, allowing you to process data. They fall into three main categories.
Arithmetic Operators: Used for mathematical calculations. + (add), - (subtract), * (multiply), / (divide), MOD (modulo, remainder), DIV (integer division).
Relational Operators: Used for comparison, they evaluate to a Boolean (true or false). or (equal to), or (not equal to), (less than), (greater than), (less than or equal to), (greater than or equal to).
Logical (Boolean) Operators: Used to combine or invert Boolean values. AND (true if both operands are true), OR (true if at least one operand is true), NOT (inverts the value, true becomes false and vice versa).
A frequent source of error in exams is confusing the assignment operator ( or ) with the equality comparison operator ( or ). When checking if two values are the same inside an IF statement, you must use the comparison operator. For example: . Assigning a value would be .
Control Structures
By default, a computer executes instructions in sequence, one after the other from top to bottom. However, to create useful programs, we need to alter this flow. Control structures allow us to make decisions (selection) and repeat actions (iteration).
Sequence: The standard line-by-line execution of code.
Selection: Uses conditions to choose which block of code to execute. The primary tool is the IF...THEN...ELSE...ENDIF structure. You can also have nested IF statements for more complex decisions.
Iteration (Looping): Repeats a block of code. The IB syllabus focuses on three types: FOR...TO...NEXT (a counted loop for when you know the number of iterations), WHILE...DO...ENDWHILE (a pre-condition loop that checks before running), and REPEAT...UNTIL (a post-condition loop that runs at least once).
Sub-routines: Methods and Functions
As programs grow, it becomes essential to organise code. Sub-routines (also known as methods, functions, or procedures) are named blocks of code designed to perform a specific, self-contained task. For example, instead of writing the code to calculate a circle's area every time you need it, you can write a single calculateCircleArea function and simply call it.
Modularity: Breaking a complex problem into smaller, simpler, solvable pieces.
Reusability: Writing code once and using it multiple times. This follows the 'Don't Repeat Yourself' (DRY) principle.
Abstraction: Hiding the complex details of an implementation. You can use the calculateCircleArea function without needing to know the exact formula inside it.
Function vs. Procedure: A function returns a value (e.g., ). A procedure performs an action but does not return a value (e.g., printWelcomeMessage()).
Parameters: Sub-routines can accept inputs, called parameters or arguments, to work with (e.g., the radius in calculateCircleArea(radius)).
In Paper 1, you will often be asked to write a sub-routine. Use clear, descriptive names for your sub-routines and parameters. For example, function calculateVat(price, rate) is much better than function calc(p, r). This improves readability and can gain you marks for clarity.
Worked examples
See the formulas applied — reveal one step at a time, like the exam.
A program is required to calculate and output the total cost of a number of cinema tickets. The price per ticket is £11.50. The program should ask the user for the number of tickets they wish to buy. Write an algorithm in pseudocode to solve this problem.
- 1
// [1] for declaring a constant with a sensible name and correct value constant TICKET_PRICE = 11.50
An array SCORES contains 20 integer test scores. Write an algorithm in pseudocode that iterates through the array, counts how many scores are 50 or greater, and outputs this count.
- 1
// Assume SCORES is a pre-populated array of 20 integers
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 be changed during the program's execution. For example, .
Key takeaways
Review these before you close the topic — retrieval beats re-reading.
- ✓
Integer: Whole numbers, positive or negative (e.g., -5, 0, 42).
- ✓
Real / Float: Numbers with a fractional part (e.g., 3.14, -0.01, 99.9).
- ✓
String: A sequence of characters, enclosed in quotes (e.g., "Hello World", "IB CS").
- ✓
Char: A single character (e.g., 'A', '!').
- ✓
Boolean: Represents logical values, can only be true or false.
Practice — then mark it
The whole point: a real Cambridge question, marked mark-by-mark.
Test Your Knowledge
Test Your Knowledge
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 Test Your Knowledge on paper, snap a photo, and get examiner-style feedback on exactly where you win and lose marks.