CS
Topic 8 Building blocks · 8.1 · 8.2 · 8.3 · 8.4 · 8.5

Building Blocks

The vocabulary of programming. Variables and constants, the five data types, INPUT and OUTPUT, arithmetic and logic operators, and how a program runs top to bottom in sequence. Every line of code you'll ever write starts here.

🧪 Exam Mode ON — recall from memory, then reveal

📚 Book Notes — start here

Read this before you tap the activities. These notes give you everything you need to feel confident before the Program Playground. When you're ready, tap 🎓 Learn.

🎯 Topic Overview

Every program you'll ever write is built from a small set of ideas: variables and constants that store data, data types that describe what kind of data (whole numbers, decimals, text, single characters, TRUE/FALSE), INPUT and OUTPUT statements that talk to the user, arithmetic operators that calculate, and sequence — the rule that says programs run top to bottom. Get these five ideas locked in and every Paper 2 program question opens up.

🎓 Learning Objectives

By the end of Topic 8.1–8.5 you should be able to…

  • Explain the difference between a variable and a constant, and choose the right one
  • Choose the correct data type (INTEGER, REAL, STRING, CHAR, BOOLEAN) for any value
  • Write pseudocode to declare variables using Cambridge syntax
  • Write programs that INPUT and OUTPUT values correctly
  • Use arithmetic operators (+, -, *, /, MOD, DIV) and predict their results
  • Use comparison operators (=, <>, >, <, >=, <=) in conditions
  • Use logical operators (AND, OR, NOT) in Boolean expressions
  • Understand that programs run in sequence — top to bottom, one line at a time

📖 Key Terminology

TermOne-line definition
VariableA named memory location whose value CAN change while the program runs.
ConstantA named memory location whose value CANNOT change once assigned.
IdentifierThe name given to a variable, constant, procedure or function.
Data typeThe category of data a variable holds: INTEGER, REAL, STRING, CHAR, BOOLEAN.
AssignmentStoring a value into a variable, using the <- operator in Cambridge pseudocode.
INPUTCambridge keyword to read a value from the user into a variable.
OUTPUTCambridge keyword to display a value (or values) to the user.
SequenceThe rule that a program executes lines top to bottom in order, unless a control structure changes the flow.
MODThe remainder operator. 17 MOD 5 = 2.
DIVThe integer division operator. 17 DIV 5 = 3.

🧠 Core Theory

The five Cambridge data types

TypeStoresExample values
INTEGERWhole numbers7, 0, -42, 1000
REALDecimal numbers3.14, -0.5, 2.0, 99.99
STRINGText (multiple characters)"hello", "cat123", ""
CHARA single character'A', '?', ' ', '7'
BOOLEANTwo states only: TRUE or FALSETRUE, FALSE

Arithmetic operators

OperatorMeaningExample
+Addition3 + 4 = 7
-Subtraction10 - 3 = 7
*Multiplication5 * 2 = 10
/Division (real result)10 / 4 = 2.5
MODRemainder after division17 MOD 5 = 2
DIVWhole part of division17 DIV 5 = 3

Comparison and logic operators

OperatorMeaning
=Equal to
<>Not equal to
<, >, <=, >=Less than, greater than, and their "or equal" versions
ANDBoth conditions must be true
ORAt least one condition must be true
NOTReverses TRUE/FALSE

💡 Worked Examples

Example 1 · Declaring and using variables

Store a person's name and age, then output them.

DECLARE Name : STRING
DECLARE Age  : INTEGER
Name <- "Alex"
Age  <- 15
OUTPUT Name, " is ", Age, " years old"

Note the syntax: DECLARE Name : STRING (colon, space, capital keyword). The assignment operator is <-, not =.

Example 2 · MOD and DIV in action

Turn 347 pence into pounds and pence:

DECLARE Pence, Pounds, Change : INTEGER
Pence  <- 347
Pounds <- Pence DIV 100    // 347 DIV 100 = 3
Change <- Pence MOD 100    // 347 MOD 100 = 47
OUTPUT Pounds, " pounds ", Change, " pence"

Output: 3 pounds 47 pence. DIV = whole part. MOD = remainder.

⚠️ Common Misconceptions

❌ Using "text" as a data type

Cambridge uses STRING. "text" is not accepted. Nor is "number" (use INTEGER or REAL), "bool" (use BOOLEAN), or "letter" (use CHAR).

❌ Confusing INPUT and OUTPUT

INPUT reads FROM the user INTO a variable. OUTPUT writes FROM a variable TO the screen. Examiners flag "an output that should have been an input" every session.

❌ Using = for assignment

The Cambridge assignment operator is <- (left arrow). Using = is a syntax error in Cambridge pseudocode — = is only for comparison.

❌ Meaningless identifiers

Names like x, data, Array or temp are marked "not meaningful". Use names that describe the value: StudentAge, TotalPrice, UserName.

❌ Mixing up MOD and DIV

DIV gives the whole part of a division (17 DIV 5 = 3). MOD gives the remainder (17 MOD 5 = 2). Learn them as a pair.

📋 Cambridge Exam Focus

Mark-winning tips from the 2023–2025 examiner reports:

Use exact Cambridge data type names. INTEGER, REAL, STRING, CHAR, BOOLEAN — capital letters, no abbreviations.
Declare variables before use. DECLARE Name : STRING is the syntax.
Assignment operator is <-, not = or :=.
Meaningful identifiers only. StudentAge, not x or data.
INPUT reads, OUTPUT writes. Never confuse the direction.
MOD = remainder, DIV = whole part. Learn them together — often tested together.
BOOLEAN has two states: TRUE and FALSE. That's the Cambridge definition of "why BOOLEAN".

🎯 Quick Knowledge Check

Tap each question to reveal the answer. Aim for at least 5 of 6.

1. What are the five Cambridge data types?
INTEGER, REAL, STRING, CHAR, BOOLEAN.
2. What's the difference between a variable and a constant?
A variable's value CAN change while the program runs. A constant's value CANNOT change once assigned.
3. What operator does Cambridge use for assignment?
<- (left arrow). Not = and not :=.
4. What is 17 MOD 5?
2. MOD gives the remainder after division. (17 ÷ 5 = 3 remainder 2.)
5. What is 17 DIV 5?
3. DIV gives the whole part of the division (17 ÷ 5 = 3 with 2 left over).
6. What does "sequence" mean in programming?
A program runs its lines top to bottom, one at a time, in order — unless a control structure (like IF, WHILE, FOR) changes the flow.

✅ Ready for activities when you can…

Name the five data types. Explain variable vs constant. Write a DECLARE line correctly. Know that <- is assignment. Predict MOD and DIV results for small numbers.

Ready? Tap the 🎓 Learn tab and try the Program Playground — step through three real programs and watch memory update live.

📚 From the Textbook

Programs store data in named spaces in memory. A variable can change during execution; a constant cannot. Every value has a data type — Cambridge uses exactly five: INTEGER (whole numbers), REAL (decimals), STRING (text), CHAR (one character), BOOLEAN (TRUE/FALSE). Programs read values with INPUT, calculate with arithmetic operators, and display results with OUTPUT. Everything runs top to bottom in sequence — that's the default flow you'll build on with selection (8.6) and iteration (8.7) later.

💡 Getting Started

Grab a scrap of paper. Draw five boxes labelled Name, Age, Height, Initial, Adult. Write "Alex" in Name, 15 in Age, 1.73 in Height, 'A' in Initial, and TRUE in Adult. Ask a friend: for each box, what data type is Cambridge asking for? (Answers: STRING, INTEGER, REAL, CHAR, BOOLEAN.) That's the mental model of memory — variables are boxes, and each box has a type.

🔬 Computer Science in Context

Every professional programming language enforces data types — even ones that feel "typeless" like Python check them at runtime. Getting types wrong is the number-one cause of bugs in real software: adding a string to a number, storing text where a number should go, or truncating a REAL to an INTEGER by accident. The habit of choosing the right type on day one saves hours of debugging later.

💬 Discussion

Why does Cambridge require you to declare a variable's type before using it? Some languages (Python, JavaScript) let you skip this — why do you think Cambridge insists on it? What's gained, what's lost?

⚖️ Variables vs Constants — pick the right one

Both are named memory locations. The difference is whether the value can change while the program runs.

📝 Variable

Value CAN change during execution.
Use for: user input, counters, running totals, results of calculations, anything that varies.
Cambridge syntax: DECLARE Age : INTEGER
Assign: Age <- 15 then later Age <- Age + 1

🔒 Constant

Value CANNOT change once set.
Use for: mathematical values (π, e), physical constants (speed of light), settings that never vary during a run (VAT rate, screen width).
Cambridge syntax: CONSTANT Pi = 3.14
Try to change it and: the program errors — that's the point.

🖥️ Program Playground — watch programs run line by line

Pick a program. Click Step. The current line highlights; variables appear as memory boxes; output prints below. This is exactly how a debugger works in a real IDE.

Pseudocode
Memory

No variables yet. Click Step to declare the first one.

Output
(nothing yet)
Click Step to begin. Each click executes one line; you'll see the memory panel light up and the output console update.

🕵️ Data Type Detective — pick the right type

A variable is described. Choose the correct Cambridge data type: INTEGER, REAL, STRING, CHAR or BOOLEAN. Instant feedback.

📝 Cambridge syntax — quick reference

The exact syntax examiners expect.

DECLARE variablesDECLARE Age : INTEGER DECLARE Name : STRING DECLARE Height : REAL DECLARE Initial : CHAR DECLARE Adult : BOOLEAN
CONSTANTCONSTANT Pi = 3.14 CONSTANT MaxSize = 100 CONSTANT AppName = "FutureLogic"
AssignmentName <- "Alex" Age <- 15 Total <- Total + 1 Ready <- TRUE
INPUT and OUTPUTINPUT Age INPUT Name, Height OUTPUT "Hello ", Name OUTPUT Total, " items cost £", Price
ArithmeticSum <- A + B Diff <- A - B Product <- A * B Quotient <- A / B Remainder <- A MOD B WholePart <- A DIV B
Comparison & logicIF Age >= 18 AND HasID = TRUE THEN IF Score <> 0 OR NOT GameOver THEN IF Grade = 'A' THEN

🎯 Six mark-scheme traps (from the examiner reports)

Trap 1 · Using "text" as a data type

"Some candidates incorrectly used text as a data type." Cambridge uses STRING. Also flagged: "number", "bool", "letter". Learn the exact five names.

Cited: 2025 s25 Q2 examiner report — verbatim

Trap 2 · Meaningless identifiers

"Many candidates used Array as the identifier for the array, which is not considered meaningful." Same for x, data, temp. Use names that describe the value.

Cited: 2024 w24 Q6(c) — recurring across sessions

Trap 3 · An OUTPUT that should have been an INPUT (or vice versa)

"Errors included… an output that should have been an input." A classic exam question — spot the wrong direction.

Cited: 2025 w25 error-finding question

Trap 4 · Wrong assignment operator

Using = for assignment is Python/Java thinking. Cambridge uses <-. = is only for equality comparison.

Cited: recurring across 2023–2025 examiner reports

Trap 5 · MOD/DIV pseudocode

"Most candidates were able to identify the correct purpose of MOD and DIV with only a few giving the correct pseudocode." Practise writing the actual expression, not just describing what they do.

Cited: 2025 s25 Q5 examiner report — verbatim

Trap 6 · Missing DECLARE

If the question says "declare and use", you must include the DECLARE line with the correct type. Skipping the declaration and going straight to the assignment loses the declaration mark. Note: if the question already declares the variables, don't re-declare — use them as given.

Cited: 2025 s25 examiner report general comments
Path

Topic 8.1–8.5 Learning Journey

Mistakes

Mistakes log

Progress

Stats & graphs

0%Accuracy
0Answered
0Streak
Bookmarks

Bookmarks

My Notes

My Notes

Title
Note
Knowledge Vault 2.0

Knowledge Vault

Add entry

Category
Confidence
Title
Info

Entries

🎮 Drill 1 — Data Type Sorter

A value or description is shown. Which of the five Cambridge data types is it?

🎮 Drill 2 — Variable or Constant?

A use case is shown. Would you declare it as a variable or a constant?

🎮 Drill 3 — Arithmetic Result Predictor

Predict the result of an arithmetic expression. Tests MOD and DIV.

🎮 Drill 4 — Fix the Declaration

A pseudocode line has an error. Pick the fix.

🎮 Drill 5 — 60-Second Building-Blocks Sprint

10 rapid questions on data types, operators, syntax. Beat your best.

60
0 / 0

✎ Practice — 18 MCQs covering 8.1 – 8.5

📋 Exam Mode — Cambridge-style questions

Every question below is drawn from a real Cambridge Paper 2 (2022–2025) or the examiner report describing that question. Type your answer, then reveal the model.

🔄 Traps — mark-scheme wording

Trap · Using "text" instead of STRING

Cambridge uses STRING. Also: INTEGER not "number", BOOLEAN not "bool", CHAR not "letter".

2025 s25 Q2 examiner report — verbatim

Trap · Meaningless identifiers (Array, x, temp, data)

Use names that describe the value: StudentAge, TotalPrice, HighestMark.

2024 w24 Q6(c), recurring

Trap · OUTPUT that should have been INPUT

Watch the direction. INPUT reads FROM user; OUTPUT writes TO screen.

2025 w25 error-finding question

Trap · = for assignment

Cambridge uses <-. The = is only for equality comparison.

Recurring across 2023–2025

Trap · Can describe MOD/DIV but can't write pseudocode

"Most candidates were able to identify the correct purpose of MOD and DIV with only a few giving the correct pseudocode." Practise the syntax.

2025 s25 Q5 examiner report — verbatim

Trap · Missing DECLARE

If the question expects declaration, don't skip it. If the question already declares variables in the scenario, use them as given — don't re-declare.

2025 s25 general comments

Trap · Wrong data type in declaration

"Errors included an incorrect data type in one of the declaration statements." Match the type to what the variable actually stores.

2025 w25 error-finding question — verbatim

Trap · NOT X vs X NOT

"Some candidates reversed the notation for NOT X with X NOT." NOT comes BEFORE the variable/condition.

2024 w24 Q7(a) — verbatim

Trap · Not using variables as given in the scenario

If the scenario names variables (e.g. StudentScores), use those exact names. Making up your own loses marks.

2025 w25 general comments

🧠 Memory triggers

IRSCB

The five Cambridge data types.
INTEGER · REAL · STRING · CHAR · BOOLEAN. Learn as one string.

MOD = Remainder, DIV = Whole

The Cambridge arithmetic pair.
17 MOD 5 = 2 (what's left over). 17 DIV 5 = 3 (how many times it divides).

Arrow, not equals

Assignment operator.
Cambridge uses <-. Python-style = is a syntax error. The = is only for equality comparison.

Variable = changing, Constant = fixed

Pick the right one.
Variable: score, counter, user input. Constant: π, VAT rate, max size — set once, never changes.

Meaningful names always

Never x, data, Array, temp.
Use StudentAge, TotalPrice, HighestMark, CurrentYear. If your identifier doesn't describe what it holds, rename it.

🏆 Skill grid

Green = secured (≥70%). Yellow = focus (30–69%). Grey = not attempted. Tap any badge to override.

✔ Saved