Topic 8 · Programming
Write Cambridge pseudocode with correct data, control structures, routines, arrays, files, and maintainable design.
8 lesson sections · 8 worked applications · Paper 2 · Cambridge 0478 (2026–2028)
Algorithm construction and careful tracing of changing variable values.
Use Cambridge syntax exactly: PascalCase identifiers, ← assignment, named terminators, and the specified library routine forms.
Programming Concepts & Data Types
The defining description of variable is “is a named storage location whose value can change while a program runs.” Connect it with constant, whose role is “is a named value that is not changed while the program runs.”
Required vocabulary and boundaries
| Idea | Precise role | Evidence or example |
|---|---|---|
| variable | is a named storage location whose value can change while a program runs | Score increases after a correct answer |
| constant | is a named value that is not changed while the program runs | TaxRate used throughout a calculation |
| programming INTEGER type | stores a whole number in a program | NumberOfStudents = 28 |
| programming REAL type | stores a program number that can contain a fractional part | Temperature = 21.5 |
| CHAR and STRING | store one character or a sequence of characters respectively | Grade = 'A' and Name = "Amina" |
| programming BOOLEAN type | stores one of the logical values TRUE or FALSE in a program | Found = FALSE |
Four-step exam routine
Identify the exact clue and name variable only when its defining role fits.
State the mechanism or boundary: is a named value that is not changed while the program runs.
Apply the idea to evidence such as “NumberOfStudents = 28.”
Reject the tempting error that stores only one text character.
Reason Before Naming
Good declarations make code easier to read and reduce mistakes when values are used later.
Start by underlining the clue in the scenario, then decide what job that clue is describing. This keeps the answer tied to the concept being assessed.
A BOOLEAN is suitable for a flag such as IsMember because it stores only TRUE or FALSE.
| Scenario clue | What it proves |
|---|---|
| value changes | variable |
| value fixed | constant |
| single character | CHAR |
| many characters | STRING |
When The Scenario Is Less Obvious
The question may include a boundary case or a tempting wrong answer. Use the exact role in the scenario as evidence.
- identifier: a name used for a variable, constant, array, or subroutine
- variable: a named value that can change while a program runs
- constant: a named value that should not change while a program runs
- data type: the kind of data a value stores
A strong answer uses the exact stored value and whether it changes as evidence.
| Term | Use in this lesson |
|---|---|
| identifier | a name used for a variable, constant, array, or subroutine |
| variable | a named value that can change while a program runs |
| constant | a named value that should not change while a program runs |
| data type | the kind of data a value stores |
A Common Mix-Up
A common mistake is choosing a data type from the example's topic instead of the actual value.
Fix: Ask whether the value changes, then match the type to the exact value being stored.
| Mistake | Correction |
|---|---|
| A common mistake is choosing a data type from the example's topic instead of the actual value. | Ask whether the value changes, then match the type to the exact value being stored. |
Basic Syntax, IO & Operators
The defining description of sequence is “executes statements in their written order unless control flow changes it.” Connect it with INPUT statement, whose role is “receives a value and stores it in a variable.”
Required vocabulary and boundaries
| Idea | Precise role | Evidence or example |
|---|---|---|
| sequence | executes statements in their written order unless control flow changes it | INPUT Price before calculating Total |
| INPUT statement | receives a value and stores it in a variable | INPUT Age |
| OUTPUT statement | displays a value, expression, or message | OUTPUT Total |
| assignment | evaluates an expression and stores the result using the left-arrow operator | Total ← Price * Quantity |
| arithmetic and relational operators | perform calculations or compare values using the defined symbols | +, −, /, *, ^ and <, <=, =, <> |
| MOD, DIV, ROUND, and RANDOM | provide remainder, integer quotient, rounding, and random-value operations | MOD(17, 5), DIV(17, 5), ROUND(Value, 2), and RANDOM() |
Four-step exam routine
Identify the exact clue and name sequence only when its defining role fits.
State the mechanism or boundary: receives a value and stores it in a variable.
Apply the idea to evidence such as “OUTPUT Total.”
Reject the tempting error that uses an equals sign only to compare two values.
Reason Before Naming
Understanding the result of each line helps predict what the program will output.
Start by underlining the clue in the scenario, then decide what job that clue is describing. This keeps the answer tied to the concept being assessed.
17 MOD 5 is 2 because 17 divided by 5 leaves a remainder of 2.
| Scenario clue | What it proves |
|---|---|
| read typed value | INPUT |
| display answer | OUTPUT |
| quotient | DIV |
| remainder | MOD |
| combine conditions | AND/OR/NOT |
When The Scenario Is Less Obvious
The question may include a boundary case or a tempting wrong answer. Use the exact role in the scenario as evidence.
- INPUT: statement that reads a value into a variable
- OUTPUT: statement that displays or sends a value
- sequence: statements running in the order written
- operator: symbol or word used to calculate or compare values
A strong answer names the statement or operator and explains the value it produces.
| Term | Use in this lesson |
|---|---|
| INPUT | statement that reads a value into a variable |
| OUTPUT | statement that displays or sends a value |
| sequence | statements running in the order written |
| operator | symbol or word used to calculate or compare values |
A Common Mix-Up
A common mistake is swapping INPUT and OUTPUT.
Fix: Say whether the statement reads, displays, calculates, compares, or combines conditions.
| Mistake | Correction |
|---|---|
| A common mistake is swapping INPUT and OUTPUT. | Say whether the statement reads, displays, calculates, compares, or combines conditions. |
Selection Constructs
The defining description of selection is “chooses which statements execute according to a condition or value.” Connect it with IF branch, whose role is “executes its statements when the Boolean condition is TRUE.”
Required vocabulary and boundaries
| Idea | Precise role | Evidence or example |
|---|---|---|
| selection | chooses which statements execute according to a condition or value | displaying Pass only when Mark >= 50 |
| IF branch | executes its statements when the Boolean condition is TRUE | IF Age >= 18 THEN |
| ELSE branch | provides an alternative when the IF condition is FALSE | outputting Not eligible |
| nested selection | places a selection statement inside another selection branch | checking membership after checking age |
| CASE statement | selects one branch according to the value of one expression | CASE OF MenuChoice |
| logical selection condition | combines Boolean tests with AND, OR, or NOT when needed | Age >= 18 AND HasID = TRUE |
Four-step exam routine
Identify the exact clue and name selection only when its defining role fits.
State the mechanism or boundary: executes its statements when the Boolean condition is TRUE.
Apply the idea to evidence such as “outputting Not eligible.”
Reject the tempting error that is forbidden at every nesting level.
Reason Before Naming
Selection makes a program respond differently to different values or conditions.
Start by underlining the clue in the scenario, then decide what job that clue is describing. This keeps the answer tied to the concept being assessed.
CASE is suitable for a menu because the same variable is compared with several exact choices.
| Scenario clue | What it proves |
|---|---|
| Score >= 50 | IF |
| MenuChoice = 1, 2, 3 | CASE |
| invalid menu value | OTHERWISE |
| false branch | ELSE |
When The Scenario Is Less Obvious
The question may include a boundary case or a tempting wrong answer. Use the exact role in the scenario as evidence.
- condition: test that is TRUE or FALSE
- IF: selection structure for a condition
- ELSE: branch used when the IF condition is false
- CASE: selection structure for one value with several possible matches
A strong answer says which branch runs and why.
| Term | Use in this lesson |
|---|---|
| condition | test that is TRUE or FALSE |
| IF | selection structure for a condition |
| ELSE | branch used when the IF condition is false |
| CASE | selection structure for one value with several possible matches |
A Common Mix-Up
A common mistake is saying IF is a loop.
Fix: Trace the TRUE or FALSE result and use indentation or ENDIF positions to keep branches clear.
| Mistake | Correction |
|---|---|
| A common mistake is saying IF is a loop. | Trace the TRUE or FALSE result and use indentation or ENDIF positions to keep branches clear. |
Iteration Constructs (Loops)
The defining description of count-controlled loop is “repeats a known number of times using a control variable.” Connect it with FOR loop update, whose role is “changes the control variable automatically through the stated range.”
Required vocabulary and boundaries
| Idea | Precise role | Evidence or example |
|---|---|---|
| count-controlled loop | repeats a known number of times using a control variable | FOR Index ← 1 TO 10 |
| FOR loop update | changes the control variable automatically through the stated range | Index takes each value from 1 to 10 |
| pre-condition loop | tests its condition before each repetition and may execute zero times | WHILE Password <> CorrectPassword DO |
| post-condition loop | executes its body before testing the condition and therefore runs at least once | REPEAT ... INPUT Value ... UNTIL Valid = TRUE |
| loop termination | requires the loop state to move toward a condition that eventually stops repetition | Count ← Count + 1 inside a WHILE loop |
| nested iteration | places one loop inside another, with no more than three levels of nested statements required | row and column loops for a table |
Four-step exam routine
Identify the exact clue and name count-controlled loop only when its defining role fits.
State the mechanism or boundary: changes the control variable automatically through the stated range.
Apply the idea to evidence such as “WHILE Password <> CorrectPassword DO.”
Reject the tempting error that tests before the first statement.
Reason Before Naming
Loop choice affects whether code runs the correct number of times.
Start by underlining the clue in the scenario, then decide what job that clue is describing. This keeps the answer tied to the concept being assessed.
A WHILE loop may run zero times because the condition is checked before the loop body.
| Scenario clue | What it proves |
|---|---|
| fixed count | FOR |
| unknown count, pre-check | WHILE |
| unknown count, post-check | REPEAT UNTIL |
When The Scenario Is Less Obvious
The question may include a boundary case or a tempting wrong answer. Use the exact role in the scenario as evidence.
- FOR loop: count-controlled loop with a known number of repeats
- WHILE loop: pre-condition loop that checks before each repeat
- REPEAT UNTIL loop: post-condition loop that checks after the body runs
- condition-controlled loop: loop controlled by a TRUE or FALSE test
A strong answer states when the condition is checked and what makes the loop stop.
| Term | Use in this lesson |
|---|---|
| FOR loop | count-controlled loop with a known number of repeats |
| WHILE loop | pre-condition loop that checks before each repeat |
| REPEAT UNTIL loop | post-condition loop that checks after the body runs |
| condition-controlled loop | loop controlled by a TRUE or FALSE test |
A Common Mix-Up
A common mistake is choosing WHILE for every repeated task.
Fix: Ask whether the count is known, whether the condition is checked before, and whether the body must run once.
| Mistake | Correction |
|---|---|
| A common mistake is choosing WHILE for every repeated task. | Ask whether the count is known, whether the condition is checked before, and whether the body must run once. |
String Handling & Library Routines
The defining description of LENGTH is “returns the number of characters in a string.” Connect it with SUBSTRING, whose role is “returns part of a string from a stated starting position and length.”
Required vocabulary and boundaries
| Idea | Precise role | Evidence or example |
|---|---|---|
| LENGTH | returns the number of characters in a string | LENGTH("CODE") returns 4 |
| SUBSTRING | returns part of a string from a stated starting position and length | extracting three characters from a product code |
| UCASE | returns a string converted to uppercase | UCASE("Seoul") gives "SEOUL" |
| LCASE | returns a string converted to lowercase | LCASE("YES") gives "yes" |
| string index origin | can begin at position zero or one according to the convention stated in the question | using the supplied first-character position |
| string-routine composition | can combine returned values in a larger expression | UCASE(SUBSTRING(Code, 1, 2)) |
Four-step exam routine
Identify the exact clue and name LENGTH only when its defining role fits.
State the mechanism or boundary: returns part of a string from a stated starting position and length.
Apply the idea to evidence such as “UCASE("Seoul") gives "SEOUL".”
Reject the tempting error that selects a random string.
Reason Before Naming
Text processing often fails because the program treats characters and numbers as if they were the same.
Start by underlining the clue in the scenario, then decide what job that clue is describing. This keeps the answer tied to the concept being assessed.
SUBSTRING("Science", 1, 3) returns "Sci" because it starts at position 1 and takes 3 characters.
| Scenario clue | What it proves |
|---|---|
| password length | LENGTH |
| first three letters | SUBSTRING |
| case-insensitive compare | UCASE/LCASE |
| calculate with digit | CHARtoNUM |
When The Scenario Is Less Obvious
The question may include a boundary case or a tempting wrong answer. Use the exact role in the scenario as evidence.
- string: sequence of characters
- LENGTH: function that returns the number of characters
- SUBSTRING: function that extracts part of a string
- UCASE/LCASE: functions that change letter case
A strong answer shows the positions or characters being counted.
| Term | Use in this lesson |
|---|---|
| string | sequence of characters |
| LENGTH | function that returns the number of characters |
| SUBSTRING | function that extracts part of a string |
| UCASE/LCASE | functions that change letter case |
A Common Mix-Up
A common mistake is forgetting that spaces are characters.
Fix: Write positions under the string, count spaces, and check whether the value is text or numeric.
| Mistake | Correction |
|---|---|
| A common mistake is forgetting that spaces are characters. | Write positions under the string, count spaces, and check whether the value is text or numeric. |
One- & Two-Dimensional Arrays
The defining description of one-dimensional array is “stores an indexed list of values of the same data type.” Connect it with two-dimensional array, whose role is “stores values addressed by two indexes such as row and column.”
Required vocabulary and boundaries
| Idea | Precise role | Evidence or example |
|---|---|---|
| one-dimensional array | stores an indexed list of values of the same data type | Marks[1:30] |
| two-dimensional array | stores values addressed by two indexes such as row and column | Seats[1:20, 1:6] |
| array declaration | states the identifier, index bounds, dimensions, and element data type | DECLARE Names : ARRAY[1:30] OF STRING |
| array index | selects a particular element and can be a variable | Marks[StudentIndex] |
| array write and read | assigns a value to an indexed element and later retrieves it using the same address | Marks[3] ← 72 then OUTPUT Marks[3] |
| array iteration | uses a loop to process a sequence of indexes and nested loops for two dimensions | visit every row and column |
Four-step exam routine
Identify the exact clue and name one-dimensional array only when its defining role fits.
State the mechanism or boundary: stores values addressed by two indexes such as row and column.
Apply the idea to evidence such as “DECLARE Names : ARRAY[1:30] OF STRING.”
Reject the tempting error that must be a fixed text string.
Reason Before Naming
Arrays reduce repeated variable names and make loops over related data easier.
Start by underlining the clue in the scenario, then decide what job that clue is describing. This keeps the answer tied to the concept being assessed.
Seats[2,5] means row 2, column 5 in a 2D array.
| Scenario clue | What it proves |
|---|---|
| five scores | 1D array |
| seat grid | 2D array |
| visit all list items | single loop |
| visit all grid cells | nested loops |
When The Scenario Is Less Obvious
The question may include a boundary case or a tempting wrong answer. Use the exact role in the scenario as evidence.
- array: data structure containing multiple values of the same type
- index: position used to access an array element
- 1D array: list accessed with one index
- 2D array: table or grid accessed with row and column indexes
A strong answer states the array name, dimension, and exact element being accessed.
| Term | Use in this lesson |
|---|---|
| array | data structure containing multiple values of the same type |
| index | position used to access an array element |
| 1D array | list accessed with one index |
| 2D array | table or grid accessed with row and column indexes |
A Common Mix-Up
A common mistake is confusing the array size with an element value.
Fix: Name the array, count the indexes, and state what each index represents.
| Mistake | Correction |
|---|---|
| A common mistake is confusing the array size with an element value. | Name the array, count the indexes, and state what each index represents. |
Subroutines & File Handling
The defining description of procedure is “a named subroutine that performs actions without returning a value.” Connect it with function, whose role is “a named subroutine that returns one value and is called inside an expression.”
Required vocabulary and boundaries
| Idea | Precise role | Evidence or example |
|---|---|---|
| procedure | a named subroutine that performs actions without returning a value | PROCEDURE DisplayMenu OUTPUT "Menu" ENDPROCEDURE |
| function | a named subroutine that returns one value and is called inside an expression | FUNCTION Total(Price : REAL, Quantity : INTEGER) RETURNS REAL |
| parameter | passes a value into a procedure or function; a subroutine may have up to three parameters and each header parameter includes its data type | Price : REAL |
| local variable | a variable available only inside the subroutine where it is declared | Subtotal declared inside a function |
| global variable | a variable available across the program | a shared GameState value |
| file operation sequence | OPENFILE in READ or WRITE mode before READFILE or WRITEFILE, followed by CLOSEFILE | reading or writing one line of text |
Four-step exam routine
Identify the exact clue and name procedure only when its defining role fits.
State the mechanism or boundary: a named subroutine that returns one value and is called inside an expression.
Apply the idea to evidence such as “Price : REAL.”
Reject the tempting error that is available everywhere in the program.
Reason Before Naming
Subroutines make programs modular, and correct file handling protects stored data.
Start by underlining the clue in the scenario, then decide what job that clue is describing. This keeps the answer tied to the concept being assessed.
A parameter is a value supplied to a subroutine so the same code can work with different inputs.
| Scenario clue | What it proves |
|---|---|
| reusable display task | procedure |
| computed value needed | function |
| different input values | parameters |
| read saved data | OPENFILE READ |
When The Scenario Is Less Obvious
The question may include a boundary case or a tempting wrong answer. Use the exact role in the scenario as evidence.
- procedure: subroutine that performs actions without returning a value
- function: subroutine that returns a value
- parameter: value passed into a subroutine
- file handling: opening, reading, writing, appending, and closing files
A strong answer names the construct and describes the data moving in or out.
| Term | Use in this lesson |
|---|---|
| procedure | subroutine that performs actions without returning a value |
| function | subroutine that returns a value |
| parameter | value passed into a subroutine |
| file handling | opening, reading, writing, appending, and closing files |
A Common Mix-Up
A common mistake is calling every subroutine a function.
Fix: Look for RETURN to identify functions, and use the file sequence open, read/write, close.
| Mistake | Correction |
|---|---|
| A common mistake is calling every subroutine a function. | Look for RETURN to identify functions, and use the file sequence open, read/write, close. |
Maintainable Programs
The defining description of meaningful identifier is “describes the purpose of a variable, constant, array, procedure, or function.” Connect it with relevant comment, whose role is “explains purpose or a non-obvious decision.”
Required vocabulary and boundaries
| Idea | Precise role | Evidence or example |
|---|---|---|
| meaningful identifier | describes the purpose of a variable, constant, array, procedure, or function | TotalScore instead of X |
| relevant comment | explains purpose or a non-obvious decision | // convert seconds to whole minutes |
| procedure used for maintainability | places a reusable action in one named subroutine so it can be changed once | one DisplayMenu procedure called from several places |
| function used for maintainability | places a reusable calculation in one returning subroutine so its logic has one point of change | one CalculateAverage function used by several reports |
| single point of change | allows repeated logic to be corrected in one subroutine | one validation procedure used by several inputs |
| readable structure | uses consistent indentation and well-scoped modules | nested IF blocks aligned clearly |
Four-step exam routine
Identify the exact clue and name meaningful identifier only when its defining role fits.
State the mechanism or boundary: explains purpose or a non-obvious decision.
Apply the idea to evidence such as “one DisplayMenu procedure called from several places.”
Reject the tempting error that is copied wherever its result is needed.
Reason Before Naming
These terms are usually assessed through short scenarios, so the mark often comes from matching the clue rather than recalling a definition alone.
Start by underlining the clue in the scenario, then decide what job that clue is describing. This keeps the answer tied to the concept being assessed.
maintainability is the best match when the scenario clue is 'future editing'.
| Scenario clue | What it proves |
|---|---|
| future editing | maintainability |
| explain purpose | comment |
| avoid repeated menu | procedure |
| show IF body | indentation |
When The Scenario Is Less Obvious
The question may include a boundary case or a tempting wrong answer. Use the exact role in the scenario as evidence.
- maintainability: how easy code is to understand and change
- meaningful identifier: name that clearly describes stored data or a subroutine
- comment: note explaining code for human readers
- indentation: spacing that shows program structure
A strong answer names the idea, quotes or paraphrases the clue, and explains the link in one sentence.
| Term | Use in this lesson |
|---|---|
| maintainability | how easy code is to understand and change |
| meaningful identifier | name that clearly describes stored data or a subroutine |
| comment | note explaining code for human readers |
| indentation | spacing that shows program structure |
A Common Mix-Up
A common mistake is stopping at a broad Maintainable Programs word instead of proving the answer from the clue.
Fix: Underline the clue first, then choose the term that explains that exact clue.
| Mistake | Correction |
|---|---|
| A common mistake is stopping at a broad Maintainable Programs word instead of proving the answer from the clue. | Underline the clue first, then choose the term that explains that exact clue. |
Turn knowledge into marks
A high-quality response does more than recall a term. It selects the command word, states the exact role, follows the mechanism in order, and connects the effect to the scenario.
Define precisely
For variable, begin with the defining role: is a named storage location whose value can change while a program runs. Do not replace the definition with an example.
Describe a process
Use an ordered chain. Name what enters, what changes or is checked, and what result follows. A useful anchor here is “NumberOfStudents = 28.”
Apply or justify
Quote the scenario need, select single point of change, then link its role — allows repeated logic to be corrected in one subroutine — to the required outcome.
Repair a misconception
Do not accept the claim that removes all whitespace. Replace it with the exact boundary: uses consistent indentation and well-scoped modules.
Mark-by-mark response ladder
- Name: use the exact syllabus term.
- Role: define what that term does or represents.
- Mechanism: describe the relevant steps in their logical order.
- Context: explain why that mechanism matters in the stated scenario.
- Boundary: avoid claiming more than the method guarantees.
Last-pass checklist
Mapped to Cambridge IGCSE Computer Science 0478 · 2026–2028 syllabus, version 5