CAIE 0478 & 9618
Variables & Types
2. Variables, Constants & Data Types
Cambridge pseudocode variable declarations, INTEGER, REAL, CHAR, STRING, BOOLEAN, DATE data types, CONSTANT definitions, and arrow (<-) assignments.
All variables must be declared using DECLARE with an explicit data type. Constants use CONSTANT. The assignment operator is <-.
Data Types
Data Type | Description | Literal Examples |
|---|---|---|
| A whole number |
|
| A number with a fractional part |
|
| A single character |
|
| A sequence of zero or more characters |
|
| Logical values |
|
| A valid calendar date |
|
Variable & Constant Declarations
PSEUDOCODE
Run in Sandbox
// runnable
DECLARE Counter : INTEGER
DECLARE TotalToPay : REAL
DECLARE GameOver : BOOLEAN
DECLARE Initial : CHAR
DECLARE StudentName : STRING
// Comma-separated declarations are also supported per exam mark schemes
DECLARE Low, High, Mid, Target : INTEGER
CONSTANT HourlyRate = 6.50
CONSTANT DefaultText = "N/A"
Assignments
PSEUDOCODE
Run in Sandbox
// runnable
// Assignment demo
DECLARE Counter : INTEGER
DECLARE TotalToPay, NumberOfHours : REAL
CONSTANT HourlyRate = 6.50
NumberOfHours <- 4
// The assignment operator is <-
Counter <- 0
Counter <- Counter + 1
TotalToPay <- NumberOfHours * HourlyRate
OUTPUT TotalToPay
Identifier Rules
- Can contain letters (A-Z, a-z), digits (0-9), and underscore (_)
- Must start with a letter, not a digit
- Should be considered case insensitive
- Keywords must never be used as variable names
- Use descriptive names (e.g.
NumberOfPlayers) — single letters are acceptable for loop conventions (e.g.i,jfor array indices)