What you'll learn
This overview covers the programming unit of CIE IGCSE Computer Science (0478): variables and constants, data types, input and output, the three basic constructs — sequence, selection and iteration — totalling and counting, string handling, arithmetic, logical and Boolean operators, nested statements, procedures and functions with parameters, library routines (MOD, DIV, ROUND, RANDOM), local and global variables, creating maintainable programs, arrays (one- and two-dimensional) and file handling. Examples use CIE pseudocode; the separate sub-topic guides cover each area in more depth.
Paper 2 tests these skills directly: reading and completing code, finding and fixing errors, and writing programs, including the longer scenario question. Clear logic and correct use of constructs earn the marks.
Key terms and definitions
Variable — A named memory location whose value can change while a program runs.
Constant — A named memory location whose value cannot change while the program runs.
Data type — The kind of data stored: INTEGER, REAL, CHAR, STRING or BOOLEAN.
Sequence — Statements executed in the order they are written.
Selection — Choosing which statements to run based on a condition: IF and CASE.
Iteration — Repeating statements: count-controlled (FOR), pre-condition (WHILE) and post-condition (REPEAT … UNTIL) loops.
Procedure — A named sub-program that performs a task and does not return a value.
Function — A named sub-program that returns a value.
Parameter — A value passed into a procedure or function.
Library routine — A pre-written routine available in the language, such as MOD, DIV, ROUND and RANDOM.
Local variable — A variable declared inside a sub-program, usable only there.
Global variable — A variable that can be used anywhere in the program.
Array — A data structure holding a fixed number of items of the same data type, accessed by index.
Core concepts
Variables, constants and data types
DECLARE Name : STRING
DECLARE Age : INTEGER
DECLARE Height : REAL
DECLARE Initial : CHAR
DECLARE IsMember : BOOLEAN
CONSTANT Pi ← 3.142
- INTEGER — whole numbers.
- REAL — numbers with a fractional part.
- CHAR — a single character.
- STRING — a sequence of characters.
- BOOLEAN — TRUE or FALSE.
Constants make programs easier to read and maintain: if the value needs to change, it is changed in one place, and it cannot be altered accidentally.
Input and output
OUTPUT "Enter your name"
INPUT Name
OUTPUT "Hello ", Name
Sequence, selection and iteration
Selection with IF:
IF Mark >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
Selection with CASE:
CASE OF Choice
1 : OUTPUT "Start"
2 : OUTPUT "Settings"
OTHERWISE : OUTPUT "Invalid"
ENDCASE
Count-controlled loop (FOR): used when the number of repetitions is known.
FOR Count ← 1 TO 5
OUTPUT Count
NEXT Count
Pre-condition loop (WHILE): the condition is checked first, so the loop may run zero times.
WHILE Number <> 0 DO
INPUT Number
ENDWHILE
Post-condition loop (REPEAT … UNTIL): the condition is checked at the end, so the loop always runs at least once — ideal for validation.
REPEAT
INPUT Password
UNTIL Password = "Secret1"
Totalling and counting
Total ← 0
Count ← 0
FOR i ← 1 TO 20
INPUT Score
Total ← Total + Score
IF Score > 70 THEN
Count ← Count + 1
ENDIF
NEXT i
Operators
- Arithmetic:
+,-,*,/,^(power),MOD(remainder),DIV(integer division). - Comparison:
=,<>,<,<=,>,>=. - Boolean:
AND,OR,NOT.
String handling
LENGTH(Word)— number of characters.SUBSTRING(Word, 1, 3)— three characters starting from position 1. (CIE pseudocode strings start at position 1.)UCASE(Word)andLCASE(Word)— convert to upper or lower case.&— joins (concatenates) strings.
Nested statements
Selection and iteration can be placed inside one another — an IF inside a loop, a loop inside a loop. Nested FOR loops are used to process two-dimensional arrays. Indentation shows the structure clearly.
Procedures and functions
PROCEDURE Greet(Name : STRING)
OUTPUT "Hello ", Name
ENDPROCEDURE
CALL Greet("Amira")
FUNCTION Square(Num : INTEGER) RETURNS INTEGER
RETURN Num * Num
ENDFUNCTION
Result ← Square(6)
Sub-programs make code modular: each part can be written and tested separately, reused, and understood more easily. Parameters pass data into them, and a function returns a value to where it was called.
Library routines
MOD(17, 5)→ 2 (remainder)DIV(17, 5)→ 3 (integer division)ROUND(3.567, 2)→ 3.57 (rounds to the given number of decimal places)RANDOM()→ a random number between 0 and 1
Local and global variables
A local variable exists only within the procedure or function where it is declared; a global variable can be used throughout the program. Local variables help prevent accidental changes and make sub-programs independent and reusable.
Maintainable programs
Programs should be easy for others to understand and update:
- meaningful identifiers for variables, constants, arrays and sub-programs;
- comments explaining the purpose of sections of code;
- procedures and functions to divide code into logical parts;
- consistent indentation.
Arrays
A one-dimensional array:
DECLARE Scores : ARRAY[1:10] OF INTEGER
Scores[1] ← 45
FOR i ← 1 TO 10
INPUT Scores[i]
NEXT i
A two-dimensional array stores a table, with the first index for the row and the second for the column:
DECLARE Grid : ARRAY[1:3, 1:4] OF CHAR
FOR Row ← 1 TO 3
FOR Col ← 1 TO 4
Grid[Row, Col] ← "."
NEXT Col
NEXT Row
File handling
Files store data permanently so it can be used again after the program closes.
OPENFILE "Scores.txt" FOR WRITE
WRITEFILE "Scores.txt", "Amira,85"
CLOSEFILE "Scores.txt"
OPENFILE "Scores.txt" FOR READ
READFILE "Scores.txt", Line
CLOSEFILE "Scores.txt"
Files must be opened in the correct mode and closed after use.
A complete scenario-style program
The longer Paper 2 question asks you to write a complete program from a description. This example stores the names and scores of 30 students, validates each score, and outputs the class average, the highest scorer and how many passed:
DECLARE Names : ARRAY[1:30] OF STRING
DECLARE Scores : ARRAY[1:30] OF INTEGER
DECLARE Total, PassCount, Highest, HighIndex, i : INTEGER
CONSTANT PassMark ← 50
Total ← 0
PassCount ← 0
Highest ← -1
HighIndex ← 0
FOR i ← 1 TO 30
OUTPUT "Enter student name"
INPUT Names[i]
REPEAT
OUTPUT "Enter score (0-100)"
INPUT Scores[i]
UNTIL Scores[i] >= 0 AND Scores[i] <= 100
Total ← Total + Scores[i]
IF Scores[i] >= PassMark THEN
PassCount ← PassCount + 1
ENDIF
IF Scores[i] > Highest THEN
Highest ← Scores[i]
HighIndex ← i
ENDIF
NEXT i
OUTPUT "Average: ", ROUND(Total / 30, 1)
OUTPUT "Top student: ", Names[HighIndex], " with ", Highest
OUTPUT "Number passed: ", PassCount
The program shows the features examiners look for: declarations with suitable data types, a constant, initialised totals and counters, validation with REPEAT … UNTIL, totalling and counting, finding a maximum, use of parallel arrays (the same index links a name to its score), a library routine (ROUND), and clear output messages.
Procedures or functions?
Use a function when the sub-program must send back a single result, such as calculating a grade or checking whether a password is valid. Use a procedure when it carries out an action, such as displaying a menu or writing data to a file. If you find yourself needing the result of a procedure elsewhere, it should probably be a function.
Testing your own code
Before finishing a programming answer, trace it with one or two test values. Check that loops start and end at the right values, that totals are initialised outside loops, that every IF has an ENDIF and every loop is closed, and that the output matches what the question asked for.
Worked examples
Example 1: Choosing a loop
Which loop should be used to keep asking for a number until it is positive? Explain. (2 marks)
Answer: A REPEAT … UNTIL loop (1), because the number must be input at least once before it can be checked (1).
Example 2: Writing a function
Write a function that returns TRUE if a number is even.
FUNCTION IsEven(Num : INTEGER) RETURNS BOOLEAN
IF MOD(Num, 2) = 0 THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDFUNCTION
Example 3: Processing an array
Write pseudocode to find the average of the 10 values in the array Scores.
Total ← 0
FOR i ← 1 TO 10
Total ← Total + Scores[i]
NEXT i
Average ← Total / 10
OUTPUT "Average: ", Average
Example 4: String handling
If Word ← "Computer", what do LENGTH(Word), SUBSTRING(Word, 4, 3) and UCASE(Word) return?
Answer: 8; "put"; "COMPUTER".
Common mistakes and how to avoid them
- Using
=for assignment. CIE pseudocode uses←for assignment and=for comparison. - Using a WHILE loop when the input must happen at least once. Use REPEAT … UNTIL.
- Starting string positions at 0. In CIE pseudocode, the first character is position 1.
- Forgetting
RETURNSandRETURNin functions. - Confusing MOD and DIV.
- Not closing files after use.
Exam technique for "Programming"
- Declare variables with suitable data types and initialise totals and counters.
- Use the construct that fits: FOR for known counts, WHILE for conditions checked first, REPEAT for validation.
- Use meaningful names, indentation and comments in longer answers — they improve clarity and marks.
- In the scenario question, read the requirements carefully and tick each one off as you write code for it.
Quick revision summary
- Data types: INTEGER, REAL, CHAR, STRING, BOOLEAN; use constants for fixed values.
- Constructs: sequence; selection (IF, CASE); iteration (FOR, WHILE, REPEAT … UNTIL).
- Totalling and counting; nested statements.
- Operators: arithmetic (incl. MOD, DIV), comparison, Boolean.
- Strings: LENGTH, SUBSTRING, UCASE, LCASE, concatenation with &.
- Procedures (no return) and functions (RETURNS a value) with parameters; library routines MOD, DIV, ROUND, RANDOM.
- Local vs global variables; maintainability through names, comments and sub-programs.
- Arrays: 1D and 2D, processed with loops. Files: OPENFILE, READFILE, WRITEFILE, CLOSEFILE.