⚡ Rapid revision — the 20-minute version
| Spine | The mark |
|---|---|
| The pattern | INPUT → PROCESS → OUTPUT — every program, every time |
| Types | Integer, real, string, boolean — '5' is TEXT, 5 is a NUMBER |
| Three structures | Sequence, selection, iteration — WHILE may run zero times |
| Operators | MOD = remainder, DIV = whole part — even/odd tests use MOD |
| Functions | Parameters in, RETURN out; locals die with the call |
| Errors | Syntax: translator refuses; runtime: crashes; logic: wrong answer — trace tables find it |
1. What a program is — instructions plus data
Program: A program is a SEQUENCE of instructions operating on DATA to produce output. Source code is translated to machine instructions: a COMPILER translates the whole program before running (produces an executable — C, Java); an INTERPRETER translates and executes LINE BY LINE (Python, JavaScript). The exam wants the trade-off: compiled runs faster and reports all syntax errors up front; interpreted runs immediately and stops at the first error.
Worked: input a temperature, compute the conversion, output the result — every program is INPUT → PROCESS → OUTPUT. Name the stage, not just the code: 'this line reads the input' is the PROCESSING pipeline, and exam questions ask you to identify it.
2. Variables and data types
Variable: A named location in memory holding a VALUE that can change. Types: INTEGER (whole numbers), REAL/FLOAT (decimals), STRING (text in quotes), BOOLEAN (true/false), CHARACTER (single symbol). DECLARATION names it; ASSIGNMENT gives it a value (x ← 5 or x = 5). CONSTANTS hold values that must NOT change (pi) — the trap: overwriting a constant is a design error even when the language permits it.
Worked: score ← 90 (integer), name ← 'Amina' (string), passed ← TRUE (boolean). '5' + 5 fails or coerces depending on the language: '5' is TEXT, 5 is a NUMBER — type mismatch is the classic runtime error. Declare the type you mean; convert explicitly (str(), int()) when mixing.
3. Control flow — sequence, selection, iteration
The three structures: Every program is built from THREE structures: SEQUENCE (one statement after another), SELECTION (if / else if / else — or case/switch: choose a path by condition), ITERATION (repeat: COUNTED for-loops when the number of repeats is known; CONDITIONAL while-loops when it depends on a condition). A while loop may run ZERO times (condition false from the start); a repeat-until loop runs AT LEAST once — the classic distinction.
Worked: print numbers 1 to 10 — counted loop (FOR i ← 1 TO 10). Keep asking for a password until correct — conditional loop (WHILE guess ≠ password). The condition is checked BEFORE the body in a while loop: if it fails first time, the body never runs. Say which loop and WHY — the justification is the mark.
4. Operators and precedence
| Family | Operators | Watch out |
|---|---|---|
| Arithmetic | + − * / MOD DIV | MOD = remainder, DIV/integer division = whole part |
| Comparison | = ≠ less greater | Comparison produces a BOOLEAN, not a number |
| Logical | AND, OR, NOT | Precedence: NOT before AND before OR |
Worked: 7 MOD 2 = 1 (remainder), 7 DIV 2 = 3 (whole part) — even/odd tests use MOD. x = 5 AND y = 3 OR z = 9 binds the AND first: (x=5 AND y=3) OR z=9. Precedence errors are logic errors — the program runs but answers wrongly, which is exactly why trace tables exist.
5. Functions — parameters, returns, scope
Function: A named, reusable block: takes PARAMETERS in, RETURNS a value out. DECLARING defines it; CALLING runs it with arguments. SCOPE: variables made INSIDE a function are LOCAL (exist only during the call); variables made outside are GLOBAL (visible everywhere — and dangerous: any code can change them). Functions exist to DECOMPOSE problems and avoid repeating code — 'write a function to...' questions pay for the parameter list and the return.
Worked: FUNCTION area(w, h) RETURN w * h — parameters w and h; the call area(4, 5) returns 20. A local total inside the function cannot be seen outside; a global total can — and a second function can silently corrupt it. Local by default is the discipline the exam rewards.
6. Input, output and validation
INPUT reads from the user (always arrives as TEXT in many languages — convert before arithmetic); OUTPUT writes results. VALIDATION checks the input is sensible BEFORE using it: range checks (age between 0 and 130), type checks, length checks, presence checks. Validation is NOT verification — it accepts plausible input; only checking against the SOURCE confirms truth. The exam's favourite loop: REPEAT input UNTIL valid.
Worked: read marks until 0–100 is entered — presence check first (not empty), range check second (0–100), then process. Skipping validation lets mark = 999 corrupt the average: garbage in, garbage out. Name the check type — 'range check' is the phrase that earns the mark.
7. Errors — the trio and how to hunt them
| Error type | Meaning | When detected |
|---|---|---|
| Syntax | Broken grammar — missing bracket, misspelt keyword | Before running (compiler/interpreter refuses) |
| Runtime | Legal grammar, impossible action — divide by zero, bad index | While running (program crashes) |
| Logic | Runs fine, wrong answer — wrong operator, off-by-one | Only by testing — the hardest to find |
DEBUGGING tools: trace tables (hand-simulate variables line by line), breakpoints (pause and inspect), print/OUTPUT statements (watch values change). The exam wants the TYPE named from a code snippet AND the tool that would find it: wrong formula = logic error = trace table; misspelt keyword = syntax = translator flags it.
8. Pseudocode and trace tables — the exam's working language
Pseudocode is structured English: ← for assignment, OUTPUT for print, INPUT for read, WHILE/FOR/IF — no language syntax to memorise, but precision still counts. A TRACE TABLE records every variable's value after each pass: columns = variables, rows = iterations. Trace questions are free marks with discipline: copy values EXACTLY, one line per loop pass, and never skip the condition test that exits the loop.
Worked: total ← 0; FOR i ← 1 TO 3: total ← total + i. Trace: i=1 total=1; i=2 total=3; i=3 total=6 — the loop accumulates 1+2+3. Off-by-one (starting total at 1, or running TO 4) shows up instantly in the trace — that is the tool's whole point.
9. Summary — the programming spine
| Question type | Method beat | Trap |
|---|---|---|
| Translate code | Trace it — variable by variable | Off-by-one at loop boundaries |
| Choose the loop | Counted = FOR; condition-dependent = WHILE | WHILE may run zero times |
| Spot the error | Syntax: translator · runtime: crash · logic: wrong answer | Logic errors pass silently |
| Write a function | Parameters IN, RETURN out, local scope | Global variables invite corruption |
| Validate input | Presence, type, range — in order | Validation accepts plausible, not true |
| Explain choice | Name the structure + the reason | No reason, no mark |
Command discipline: 'write pseudocode' = assignment arrows, INPUT/OUTPUT, one structure per line — no language syntax; 'trace' = a table, one row per iteration, values copied exactly; 'explain' = structure + reason in one sentence. Programming papers pay for the TRACE — a guessed output without the trace earns half.