Wimzee Cambridge Academy
← All Revision Notes← IGCSE Computer Science

Programming

Revision Notes — IGCSE
CAIE IGCSE Computer Science (0478) • Topic 8 of 10 • Paper 1 & Paper 2
Mastered: 0 / 2

8.1 Variables, Constants and Data Types

TermMeaning
VariableA named store whose value can change while the program runs
ConstantA named value that cannot change once set (e.g. PI, VAT_RATE); prevents accidental change and makes code readable
IntegerA whole number, e.g. 42
RealA number with a decimal part, e.g. 3.75
CharA single character, e.g. 'A'
StringA sequence of characters, e.g. "Hello"
BooleanTRUE 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.

DECLARE scores : ARRAY[1:30] OF INTEGER scores[1] ← 78 DECLARE grid : ARRAY[1:3,1:3] OF INTEGER grid[2,3] ← 9 // row 2, column 3

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

ConstructPurposePseudocode
SequenceStatements run in orderone statement after another
SelectionChoose a pathIF … THEN … ELSE … ENDIF; CASE OF … ENDCASE
IterationRepeat statementsFOR … NEXT; WHILE … DO … ENDWHILE; REPEAT … UNTIL
// FOR - known number of repetitions FOR i ← 1 TO 10 OUTPUT i NEXT i // WHILE - condition checked before the loop (may run zero times) WHILE answer <> "yes" DO INPUT answer ENDWHILE // REPEAT - condition checked after the loop (runs at least once) REPEAT INPUT password UNTIL password = "secret"

8.4 String Handling

FunctionReturns
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 / DIVRemainder / 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

ProcedureFunction
Returns a value?NoYes — it must return exactly one value
Called byA statement on its ownInside an expression or assignment
ExampleCALL 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

OPEN "scores.txt" FOR READ WHILE NOT EOF("scores.txt") READ "scores.txt", score total ← total + score ENDWHILE CLOSE "scores.txt" OPEN "output.txt" FOR WRITE WRITE "output.txt", "Average: ", average CLOSE "output.txt"

8.7 Standard Algorithms

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

  1. State the data type you would use for a price, a postcode and a yes/no flag.
  2. Write pseudocode to total the values in a 1D array of 10 integers.
  3. Give two differences between a procedure and a function.
  4. Explain the difference between a local and a global variable.
  5. Write pseudocode to find the largest value in an array.
Exam practice 1[6]

Write a program that reads 10 numbers into an array, then outputs the total and the average.

Mark scheme
  • 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 / 10 then OUTPUT average (1).
Exam practice 2[5]

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.

Mark scheme
  • 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).

Quick Reference

Variable changes, constant does not Types: INTEGER, REAL, CHAR, STRING, BOOLEAN Sequence, selection (IF/CASE), iteration (FOR/WHILE/REPEAT) FOR = known count; WHILE = test first; REPEAT = test last Procedure returns nothing; function returns one value Local = inside subprogram; global = anywhere File: OPEN -> READ/WRITE -> CLOSE