8.1 Variables, Constants and Data Types
| Term | Meaning |
|---|---|
| Variable | A named store whose value can change while the program runs |
| Constant | A named value that cannot change once set (e.g. PI, VAT_RATE); prevents accidental change and makes code readable |
| Integer | A whole number, e.g. 42 |
| Real | A number with a decimal part, e.g. 3.75 |
| Char | A single character, e.g. 'A' |
| String | A sequence of characters, e.g. "Hello" |
| Boolean | TRUE or FALSE |
Choose the data type that uses the least storage while still holding the required values — for example, use an integer for a number of students, a real for a price, a Boolean for a yes/no flag.
8.2 Arrays
An array stores several values of the same data type under one name, accessed by an index. A 1D array is a single list; a 2D array is a table of rows and columns.
Arrays are used with loops: a FOR loop from the first to the last index processes every element without repeating code.
8.3 The Three Constructs
| Construct | Purpose | Pseudocode |
|---|---|---|
| Sequence | Statements run in order | one statement after another |
| Selection | Choose a path | IF … THEN … ELSE … ENDIF; CASE OF … ENDCASE |
| Iteration | Repeat statements | FOR … NEXT; WHILE … DO … ENDWHILE; REPEAT … UNTIL |
8.4 String Handling
| Function | Returns |
|---|---|
LENGTH(s) | The number of characters in the string |
SUBSTRING(s, start, length) | Part of the string |
UCASE(s) / LCASE(s) | The string in upper or lower case |
LEFT(s, n) / RIGHT(s, n) | The first or last n characters |
INT(x) | The whole-number part of a real |
MOD / DIV | Remainder / whole-number quotient |
ROUND(x, n) | The value rounded to n decimal places |
RANDOM(n) | A random integer between 1 and n |
8.5 Procedures and Functions
| Procedure | Function | |
|---|---|---|
| Returns a value? | No | Yes — it must return exactly one value |
| Called by | A statement on its own | Inside an expression or assignment |
| Example | CALL PrintHeading("Results") | average ← CalcAverage(total, count) |
Parameters are the values passed into a subprogram. Passing by value copies the value, so the original is unchanged; passing by reference passes the address, so the subprogram can change the original variable. Local variables exist only inside a subprogram; global variables can be used anywhere, which makes programs harder to debug.
8.6 File Handling
8.7 Standard Algorithms
- Totalling — start at 0 and add each value.
- Counting — start at 0 and add 1 each time a condition is met.
- Maximum / minimum — set the first value as the current max/min, then compare every other value.
- Average — total ÷ count (check the count is not zero).
- Linear search — loop through the array, stop when found.
Exam trap
Use a WHILE loop when the number of repetitions is unknown and a FOR loop when it is known. Using a FOR loop for "keep asking until the user enters a valid value" is a common lost mark.
Five-minute drill
- State the data type you would use for a price, a postcode and a yes/no flag.
- Write pseudocode to total the values in a 1D array of 10 integers.
- Give two differences between a procedure and a function.
- Explain the difference between a local and a global variable.
- Write pseudocode to find the largest value in an array.
Write a program that reads 10 numbers into an array, then outputs the total and the average.
DECLARE numbers : ARRAY[1:10] OF REAL(1).total ← 0(1).FOR i ← 1 TO 10…INPUT numbers[i]…NEXT i(1).- Inside the loop or a second loop:
total ← total + numbers[i](1). OUTPUT total(1).average ← total / 10thenOUTPUT average(1).
A program must keep asking the user to enter a password until it matches "Wimzee2026". Write pseudocode for this, and state why a REPEAT loop is suitable.
REPEAT(1);INPUT password(1);UNTIL password = "Wimzee2026"(1).- A REPEAT loop checks the condition after the body (1), so the user is always asked at least once — which is what is needed here (1).