In the IGCSE exam, Paper 2 requires you to write complete pseudocode programs — not just snippets. This lesson consolidates all the elements you have learned: variables, selection, iteration, arrays, procedures/functions, and file handling — combined into complete solutions.
| Concept | Pseudocode |
|---|---|
| Variable assignment | x ← 42 |
| Input | INPUT name |
| Output | OUTPUT "Hello " & name |
| Declare variable | DECLARE count : INTEGER |
| IF statement | IF x > 0 THEN...ELSE...ENDIF |
| CASE OF | CASE OF x; 1: ...; OTHERWISE: ...; ENDCASE |
| FOR loop | FOR i ← 1 TO 10; ...; NEXT i |
| WHILE loop | WHILE cond DO; ...; ENDWHILE |
| REPEAT loop | REPEAT; ...; UNTIL cond |
| Array declare | DECLARE arr : ARRAY[1:10] OF INTEGER |
| Array access | arr[i] |
| Procedure | PROCEDURE name(p:TYPE); ...; ENDPROCEDURE; CALL name(arg) |
| Function | FUNCTION name(p:TYPE) RETURNS TYPE; ...; RETURN val; ENDFUNCTION; x ← name(arg) |
| File read | OPENFILE "f" FOR READ; READFILE "f", v; CLOSEFILE "f" |
| File write | OPENFILE "f" FOR WRITE; WRITEFILE "f", data; CLOSEFILE "f" |
| String length | LENGTH(s) |
| Substring | SUBSTRING(s, start, length) |
| Arithmetic | +, -, *, /, DIV (integer div), MOD (remainder) |
| Comparison | =, <>, <, >, <=, >= |
| Boolean | AND, OR, NOT |
// Reads 5 exam scores and outputs grades
DECLARE scores : ARRAY[1:5] OF INTEGER
DECLARE i : INTEGER
DECLARE total : INTEGER
total ← 0
FOR i ← 1 TO 5
INPUT scores[i]
total ← total + scores[i]
NEXT i
average ← total / 5
IF average >= 70 THEN
OUTPUT "Grade A"
ELSE IF average >= 60 THEN
OUTPUT "Grade B"
ELSE IF average >= 50 THEN
OUTPUT "Grade C"
ELSE
OUTPUT "Fail"
ENDIF
OUTPUT "Average: " & average
// Validates a number between 1 and 100
DECLARE guess : INTEGER
REPEAT
OUTPUT "Enter a number between 1 and 100:"
INPUT guess
UNTIL guess >= 1 AND guess <= 100
OUTPUT "Valid guess: " & guess
// Counts records in a file
DECLARE line : STRING
DECLARE count : INTEGER
count ← 0
OPENFILE "data.txt" FOR READ
WHILE NOT EOF("data.txt") DO
READFILE "data.txt", line
count ← count + 1
ENDWHILE
CLOSEFILE "data.txt"
OUTPUT "Total records: " & count
| Iteration | guess (INPUT) | guess >= 1 AND guess <= 100 | Loop continues? |
|---|---|---|---|
| 1 | 150 | FALSE | Yes (repeat) |
| 2 | -5 | FALSE | Yes (repeat) |
| 3 | 42 | TRUE | No (exit) |
3 questions · 12 marks
| Term | Definition |
|---|
10 minutes · mixed marks