Section 1: The Fundamentals

Variables, Constants & Data Types

The foundation of all programming logic. Learn the rules for declaring identifiers, assigning data, and interacting with users.

1. What is a Variable?

A variable is simply a named location in the computer's memory where data can be stored, changed, and retrieved while a program is running. Think of it like a labeled box where you can put a value inside.

2. Identifier Naming Rules

In the Cambridge syllabus, the name you give to a variable or constant is called an identifier. You cannot just name a variable whatever you want. Examiners look for these strict rules:

3. Declaring Variables

Unlike modern high-level languages (like Python) that let you create variables on the fly, standard Cambridge pseudocode strictly requires you to declare all variables and their specific data types before you can use them.

Declaration & Assignment
// Keyword VariableName : DataType
DECLARE PlayerScore : INTEGER
DECLARE PlayerName : STRING

// Assigning values requires the arrow (←)
PlayerScore ← 0
PlayerName ← "Alice"

4. Common Data Types

When declaring a variable, you must specify its data type. Here are the core data types you need to know for your exams:

INTEGER

A whole number without a fractional part. (e.g., 10, -5, 0)

REAL

A number that contains a decimal point. (e.g., 3.14, -0.5)

STRING

A sequence of alphanumeric characters enclosed in speech marks. (e.g., "Hello World")

BOOLEAN

A logical value that can only be TRUE or FALSE.

5. Constants

Sometimes you need to store a value that should never change while the program is running (like Pi, or a VAT tax rate). For this, we use the CONSTANT keyword instead of DECLARE. Constants are traditionally written in ALL CAPS.

Constant Syntax
CONSTANT PI ← 3.142
CONSTANT MAX_PLAYERS ← 4

6. INPUT and OUTPUT

To make your program interactive, you need to display messages to the screen and read data typed by the user.

IO Syntax
DECLARE UserAge : INTEGER

OUTPUT "Please enter your age: "
INPUT UserAge

OUTPUT "Next year, you will be: ", UserAge + 1

Exam Strategy: Python vs. Pseudocode

Examiners routinely deduct points for "Syntax Soup." If you learned Python first, you must unlearn these habits for the Cambridge written exam:

Concept 🐍 Python (Wrong for Exams) 📘 Cambridge Pseudocode (Correct)
Assignment score = 10 Score ← 10
Output print("Hello") OUTPUT "Hello"
Input age = input("Enter age") OUTPUT "Enter age"
INPUT Age

Interactive Exam Practice

Scenario: Ask the user for the radius of a circle. Calculate the area (Area = Pi * Radius * Radius) and output the result. Use a constant for Pi.

Hover over the black box to reveal the examiner's solution. Click Run Code to test it instantly in our IDE!

Hover to Reveal Answer
CONSTANT PI ← 3.142
DECLARE Radius : REAL
DECLARE Area : REAL

OUTPUT "Enter the radius:"
INPUT Radius

Area ← PI * Radius * Radius

OUTPUT "The area of the circle is: ", Area