What is Programming in IGCSE Computer Science?

Programming is the process of designing, writing, testing, and refining a set of instructions that a computer can execute to solve a problem or perform a task. Within the Cambridge IGCSE Computer Science (0478) syllabus, programming occupies a central position: it connects the theoretical understanding of algorithms to practical problem-solving, and it is assessed directly in Paper 2. A strong grasp of programming concepts - including variables, data types, control structures, arrays, and file handling - is essential for achieving high marks.

All code examples in these notes follow the Cambridge pseudocode syntax, which is the notation used in examination papers. Mastering this pseudocode is just as important as understanding the underlying logic, because marks in the exam depend on correct use of the prescribed syntax.

Variables, Constants, and Data Types

Variables and Constants

A variable is a named storage location in memory whose value can change during the execution of a program. A constant is a named value that is set once and does not change. In Cambridge pseudocode, declarations look like this:

DECLARE Counter : INTEGER
DECLARE StudentName : STRING
CONSTANT Pi = 3.14159
CONSTANT MaxSize = 100

Using constants rather than hard-coded literal values makes programs easier to maintain: if a value needs to change, only the constant declaration is updated, rather than every line where the value appears.

Data Types

The IGCSE syllabus specifies five core data types. The table below summarises each one with its purpose and an example value.

Data TypeDescriptionExample Values
INTEGERWhole numbers (positive, negative, or zero)0, 42, -7
REALNumbers with a fractional (decimal) part3.14, -0.5, 100.0
CHARA single character'A', '7', '#'
STRINGA sequence of zero or more characters"Hello", "IGCSE", ""
BOOLEANA logical value: TRUE or FALSETRUE, FALSE
Exam Tip: Examiners frequently test whether candidates can choose the correct data type for a given scenario. A common error is declaring a telephone number as INTEGER. Because leading zeros matter and no arithmetic is performed on phone numbers, they should be stored as STRING.

Input and Output

Programs communicate with the user through input and output statements. In Cambridge pseudocode, these are:

OUTPUT "Enter your name: "
INPUT Name
OUTPUT "Hello, ", Name

INPUT reads a value from the user and stores it in a variable. OUTPUT displays a value (or a combination of values and literal strings) on screen.

Control Structures

Sequence

Sequence is the default mode of execution: statements are carried out one after another, in the order they are written. Every program relies on sequence as its foundation, even when selection and iteration structures are layered on top.

Selection

Selection allows a program to choose between different paths of execution based on a condition.

IF...THEN...ELSE:

IF Score >= 50
  THEN
    OUTPUT "Pass"
  ELSE
    OUTPUT "Fail"
ENDIF

Nested IF:

IF Score >= 80
  THEN
    OUTPUT "Distinction"
  ELSE
    IF Score >= 50
      THEN
        OUTPUT "Pass"
      ELSE
        OUTPUT "Fail"
    ENDIF
ENDIF

CASE OF: When multiple discrete values must be tested, a CASE statement is cleaner than a chain of IF statements.

CASE OF Grade
  "A" : OUTPUT "Excellent"
  "B" : OUTPUT "Good"
  "C" : OUTPUT "Satisfactory"
  OTHERWISE OUTPUT "Below expected"
ENDCASE

Iteration (Loops)

Iteration repeats a block of code. The IGCSE syllabus requires three types of loop, each suited to different situations.

Loop TypeWhen to UseCondition CheckedMin Iterations
FOR...NEXTNumber of repetitions is knownAt start (counter-controlled)0 (if start > end)
WHILE...DO...ENDWHILENumber of repetitions is not known; may execute zero timesAt start (pre-condition)0
REPEAT...UNTILNumber of repetitions is not known; must execute at least onceAt end (post-condition)1

Examples in pseudocode:

// FOR loop
FOR Index = 1 TO 10
  OUTPUT Index
NEXT Index

// WHILE loop
WHILE Response <> "quit" DO
  INPUT Response
ENDWHILE

// REPEAT...UNTIL loop
REPEAT
  INPUT Password
UNTIL Password = "secret"

Totalling and Counting

Two fundamental patterns appear repeatedly in programming questions on the IGCSE examination.

  • Totalling: A running total accumulates values. Initialise a variable to zero, then add each new value inside a loop.
  • Counting: A counter tracks how many times an event occurs. Initialise to zero, then increment by one each time the condition is met.
DECLARE Total : REAL
DECLARE Count : INTEGER
Total = 0
Count = 0
FOR Index = 1 TO 20
  INPUT Mark
  Total = Total + Mark
  IF Mark >= 50
    THEN
      Count = Count + 1
  ENDIF
NEXT Index
OUTPUT "Sum: ", Total
OUTPUT "Number of passes: ", Count

String Handling

Cambridge pseudocode provides built-in functions for manipulating strings. These are frequently tested, so familiarity with their syntax is essential.

FunctionPurposeExampleResult
LENGTH(s)Returns the number of charactersLENGTH("Code")4
SUBSTRING(s, start, length)Extracts a portion of a stringSUBSTRING("Hello", 2, 3)"ell"
UCASE(s)Converts to uppercaseUCASE("hello")"HELLO"
LCASE(s)Converts to lowercaseLCASE("Hello")"hello"
Key Point: In Cambridge pseudocode, SUBSTRING uses 1-based indexing. The first character of the string is at position 1, not position 0. Candidates who are used to Python (0-based indexing) must take care to adjust.

Procedures and Functions

Breaking a program into smaller, reusable blocks is a core principle of structured programming. The IGCSE syllabus distinguishes between procedures and functions.

  • A procedure performs a task but does not return a value.
  • A function performs a task and returns a value to the calling code.

Procedure with parameters:

PROCEDURE PrintGreeting(Name : STRING)
  OUTPUT "Welcome, ", Name
ENDPROCEDURE

CALL PrintGreeting("Amir")

Function with a return value:

FUNCTION CalculateArea(Length : REAL, Width : REAL) RETURNS REAL
  RETURN Length * Width
ENDFUNCTION

DECLARE Area : REAL
Area = CalculateArea(5.0, 3.5)
OUTPUT Area

Local and Global Variables

A local variable is declared inside a procedure or function and exists only while that subroutine is executing. A global variable is declared in the main program and is accessible from anywhere. The IGCSE syllabus expects candidates to understand why local variables are generally preferred: they reduce the risk of unintended side effects, make subroutines self-contained, and simplify debugging. Global variables should be used sparingly, typically only when a value genuinely needs to be shared across multiple parts of a program.

Arrays

One-Dimensional (1D) Arrays

An array stores a fixed-size collection of elements of the same data type, accessed by an index. In Cambridge pseudocode, arrays use 1-based indexing by default.

DECLARE Names : ARRAY[1:30] OF STRING
Names[1] = "Fatima"
Names[2] = "Chen"
OUTPUT Names[1]

Iterating through an array to display all elements:

FOR Index = 1 TO 30
  OUTPUT Names[Index]
NEXT Index

Two-Dimensional (2D) Arrays

A 2D array can be visualised as a table with rows and columns. It requires two indices to access an element.

DECLARE Grid : ARRAY[1:5, 1:3] OF INTEGER
Grid[2, 3] = 42
OUTPUT Grid[2, 3]

A nested loop is typically used to process every element:

FOR Row = 1 TO 5
  FOR Col = 1 TO 3
    OUTPUT Grid[Row, Col]
  NEXT Col
NEXT Row

Common Array Algorithms

Linear Search: Examines each element in turn until the target is found or the end of the array is reached.

DECLARE Found : BOOLEAN
Found = FALSE
FOR Index = 1 TO 30
  IF Names[Index] = "Chen"
    THEN
      OUTPUT "Found at position ", Index
      Found = TRUE
  ENDIF
NEXT Index
IF Found = FALSE
  THEN
    OUTPUT "Not found"
ENDIF

Bubble Sort: Repeatedly compares adjacent elements and swaps them if they are in the wrong order. Each pass moves the largest unsorted element to its correct position.

DECLARE Temp : INTEGER
FOR i = 1 TO 9
  FOR j = 1 TO 10 - i
    IF Numbers[j] > Numbers[j + 1]
      THEN
        Temp = Numbers[j]
        Numbers[j] = Numbers[j + 1]
        Numbers[j + 1] = Temp
    ENDIF
  NEXT j
NEXT i

File Handling

Programs often need to store data permanently, beyond the lifetime of a single execution. File handling allows a program to read data from, and write data to, external text files. The IGCSE examination tests three file operations: reading, writing, and appending.

File Modes

ModePurposeEffect on Existing Data
READRead data from a fileNo change
WRITEWrite new data to a fileOverwrites all existing data
APPENDAdd data to the end of a filePreserves existing data

Reading from a File

OPENFILE "students.txt" FOR READ
WHILE NOT EOF("students.txt") DO
  READFILE "students.txt", Line
  OUTPUT Line
ENDWHILE
CLOSEFILE "students.txt"

The EOF function returns TRUE when all lines have been read, preventing the program from attempting to read past the end of the file.

Writing to a File

OPENFILE "results.txt" FOR WRITE
WRITEFILE "results.txt", "Score: 85"
CLOSEFILE "results.txt"

Appending to a File

OPENFILE "log.txt" FOR APPEND
WRITEFILE "log.txt", "New entry added"
CLOSEFILE "log.txt"
Exam Tip: A common error in examinations is forgetting to close the file after use. Always pair every OPENFILE with a corresponding CLOSEFILE. Examiners will deduct marks for missing CLOSEFILE statements.

Worked Exam-Style Questions

Question 1

A teacher stores 30 test marks in a file called "marks.txt". Write a program in pseudocode that reads all 30 marks from the file, calculates the average, and outputs how many students scored above the average.

Model Answer:
DECLARE Marks : ARRAY[1:30] OF REAL
DECLARE Total : REAL
DECLARE Average : REAL
DECLARE AboveCount : INTEGER
Total = 0
AboveCount = 0

OPENFILE "marks.txt" FOR READ
FOR Index = 1 TO 30
  READFILE "marks.txt", Marks[Index]
  Total = Total + Marks[Index]
NEXT Index
CLOSEFILE "marks.txt"

Average = Total / 30

FOR Index = 1 TO 30
  IF Marks[Index] > Average
    THEN
      AboveCount = AboveCount + 1
  ENDIF
NEXT Index

OUTPUT "Average: ", Average
OUTPUT "Students above average: ", AboveCount

This solution uses two passes: the first reads data and totals, the second counts values above the computed average. Storing the marks in an array is essential because the average is not known until all values have been read.

Question 2

Write a function called CountVowels that takes a string as a parameter and returns the number of vowels (A, E, I, O, U) in that string. The function should be case-insensitive.

Model Answer:
FUNCTION CountVowels(Text : STRING) RETURNS INTEGER
  DECLARE Count : INTEGER
  DECLARE UpperText : STRING
  DECLARE Ch : CHAR
  Count = 0
  UpperText = UCASE(Text)
  FOR Index = 1 TO LENGTH(UpperText)
    Ch = SUBSTRING(UpperText, Index, 1)
    IF Ch = 'A' OR Ch = 'E' OR Ch = 'I' OR Ch = 'O' OR Ch = 'U'
      THEN
        Count = Count + 1
    ENDIF
  NEXT Index
  RETURN Count
ENDFUNCTION

Converting to uppercase first means only five comparisons are needed per character, rather than ten. This is a clean example of how string functions and iteration work together.

Common Mistakes to Avoid

The following errors appear frequently in candidate responses across past IGCSE Computer Science examinations.

  • Uninitialised counters and totals: Forgetting to set a counter or total to 0 before a loop begins. The accumulator must always start from a known value.
  • Off-by-one errors in loops: Using FOR Index = 0 TO 9 when the array is declared as ARRAY[1:10]. Cambridge pseudocode arrays are 1-based unless declared otherwise.
  • Wrong loop type: Using a FOR loop when the number of iterations is unknown (e.g., reading until a sentinel value). Use WHILE or REPEAT instead.
  • Confusing WRITE and APPEND: Opening a file in WRITE mode erases its previous contents. To add data without losing what is already there, use APPEND.
  • Missing CLOSEFILE: Every file opened must be closed. This is a mark-bearing step.
  • Confusing procedures and functions: A function must contain a RETURN statement and must be called as part of an expression or assignment. A procedure is called with CALL and does not return a value.
  • Incorrect SUBSTRING indexing: The first character is at position 1 in Cambridge pseudocode. Candidates familiar with Python's 0-based indexing often make errors here.
  • Not declaring variables: Cambridge pseudocode expects explicit DECLARE statements. Losing a mark for an undeclared variable is easily avoidable.

Self-Check Questions

Test your understanding of the topics covered above. Try to answer each question before checking the explanation.

  1. What data type would you use to store whether a student has submitted their homework?
    BOOLEAN. The value is either TRUE (submitted) or FALSE (not submitted). No other data type captures this two-state condition as precisely.
  2. A WHILE loop and a REPEAT...UNTIL loop both handle an unknown number of iterations. What is the key difference?
    A WHILE loop checks its condition before executing the loop body, so the body may never execute (zero iterations). A REPEAT...UNTIL loop checks its condition after executing the body, so the body always executes at least once.
  3. An array is declared as DECLARE Scores : ARRAY[1:50] OF INTEGER. How would you assign the value 95 to the 25th element?
    Scores[25] = 95
  4. Explain why a telephone number should be stored as a STRING rather than an INTEGER.
    Telephone numbers may have leading zeros (e.g., 07123456789), which would be lost if stored as an integer. No arithmetic operations are performed on telephone numbers, so numeric storage offers no advantage.
  5. What is the output of SUBSTRING("CAMBRIDGE", 4, 3)?
    "BRI". Starting at position 4 (the character 'B') and extracting 3 characters gives "BRI".

Download de app in de Google Playstore

Alles wat je nodig hebt om uit te blinken in JAMB, WAEC en NECO.

Green Bridge CBT Mobile App
Persoonlijke AI Leerchat Assistent
Duizenden IGCSE, JAMB-, WAEC- en NECO-examenvragen uit het verleden.
Meer dan 1200 lesnotities
Offline ondersteuning - Leer altijd en overal
Dienstregeling Groene Brug
Literatuursamenvattingen & Potentiƫle Vragen
Volg je prestaties en vooruitgang.
Diepgaande Uitleg voor Uitgebreid Leren
Kort samengevat

Complete revision notes on programming for Cambridge IGCSE Computer Science (0478), covering variables, data types, control structures, arrays, file handling, procedures, and functions. Includes worked exam-style questions, common mistakes, and self-check exercises, all presented in Cambridge pseudocode syntax.