← IGCSE Computer Science Paper 2

What a subroutine is

A named block of code, written once, that runs whenever it is called. Procedures and functions are the two kinds, and they break a program into parts.

Understanding What a subroutine is in IGCSE Computer Science Paper 2

What it does: A function is a subroutine that uses RETURN to send a value back, while a procedure does not return a value. One definition is reused by three calls, so the code is written once but run three times. A subroutine is a named block of statements. It does not store data like a variable does; it runs when you call it. A subroutine is defined once. Each time you need it, you call it by name instead of rewriting the code. Procedures and functions are the two kinds of subroutine. Loops and arrays are different programming ideas. Subroutines divide a large program into smaller parts. Each part has a name and does one job.

Common mistakes: A subroutine is defined with the keyword PROCEDURE (or FUNCTION), not SUBROUTINE. The first line should be PROCEDURE Countdown(). Text to be displayed must be in quotation marks. The line should be OUTPUT "Welcome!". The procedure is written once and then called twice.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 389–398) and word search (Modules 379–398).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which describes a subroutine best?
A named block of code that runs when it is calledA variable that stores a number for later
Matches
PROCEDURE ShowMenu() OUTPUT "1. Play" CALL ShowMenu()
↓
The procedure has no ENDPROCEDURE, so the block of statements is never closed and the subroutine is not properly defined.
Applying
Meanings
Term
subroutine
Meaning
A named block of code, written once, that runs whenever it is called. Procedures and functions are the two kinds, and they break a program into parts.
Practice
PROCEDURE Welcome()
Testing
Gaps
ShowMenu()
Check Answer
Spots
1SUBROUTINE Countdown()
2 OUTPUT "3 2 1 Go!"

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Gila Monster' badge — Patient Coder, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which describes a subroutine best?
A. A named block of code that runs when it is called ✓
B. A variable that stores a number for later
A subroutine is a named block of statements. It does not store data like a variable does; it runs when you call it.
2. How many times must you write the code inside a subroutine?
A. Again every time you want it to run
B. Once, then call it whenever needed ✓
A subroutine is defined once. Each time you need it, you call it by name instead of rewriting the code.
3. What are the two kinds of subroutine in IGCSE pseudocode?
A. Procedures and functions ✓
B. Loops and arrays
Procedures and functions are the two kinds of subroutine. Loops and arrays are different programming ideas.
4. Why do programmers break a program into subroutines?
A. It makes the program run without a computer
B. It splits the program into smaller named parts ✓
Subroutines divide a large program into smaller parts. Each part has a name and does one job.
5. When does the code inside a subroutine run?
A. When the subroutine is called ✓
B. As soon as it is defined
Defining a subroutine only describes it. The code inside runs when the subroutine is called.

Match the Pairs

PROCEDURE ShowMenu() OUTPUT "1. Play" ENDPROCEDURE → A named block of statements that is defined once and does a job when it is called
CALL ShowMenu() → Runs the subroutine named ShowMenu, then control returns to the next line
The two kinds of subroutine are procedures and functions, and a function gives back a value → FUNCTION Double(n : INTEGER) RETURNS INTEGER RETURN n * 2 ENDFUNCTION
A subroutine is defined once and can be called many times → CALL ShowMenu() CALL ShowMenu() CALL ShowMenu()
PROCEDURE ShowMenu() OUTPUT "1. Play" CALL ShowMenu() → The procedure has no ENDPROCEDURE, so the block of statements is never closed and the subroutine is not properly defined.
OUTPUT "1. Play" OUTPUT "1. Play" OUTPUT "1. Play" → The same statements are copied out each time instead of being written once in a subroutine and called.

Key Term

subroutine
A named block of code, written once, that runs whenever it is called. Procedures and functions are the two kinds, and they break a program into parts.

Fill in the Blanks

1. PROCEDURE ShowMenu() OUTPUT "Welcome" ENDPROCEDURE
Hint: Type the keyword that starts the definition of a subroutine that does not return a value.
2. CALL ShowMenu() OUTPUT "Pick an option" CALL ShowMenu()
Hint: Type the keyword that runs a procedure that was already defined. It can be used again and again.
3. FUNCTION Double(N : INTEGER) RETURNS INTEGER RETURN N * 2 ENDFUNCTION
Hint: Type the keyword that states which data type the function sends back.
4. PROCEDURE DrawLine() OUTPUT "----------" ENDPROCEDURE
Hint: Type the keyword that closes the block of statements making up the procedure.
5. FUNCTION Five() RETURNS INTEGER RETURN 5 ENDFUNCTION
Hint: Type the keyword a function uses to send a value back to the code that called it.

Spot the Error

Question 1
A SUBROUTINE Countdown()
B OUTPUT "3 2 1 Go!"
C ENDPROCEDURE
D CALL Countdown()
Line A — A subroutine is defined with the keyword PROCEDURE (or FUNCTION), not SUBROUTINE. The first line should be PROCEDURE Countdown().
Question 2
A PROCEDURE Welcome()
B OUTPUT Welcome!
C ENDPROCEDURE
D CALL Welcome()
E CALL Welcome()
Line B — Text to be displayed must be in quotation marks. The line should be OUTPUT "Welcome!". The procedure is written once and then called twice.
Question 3
A FUNCTION GetPi() RETURNS REAL
B OUTPUT 3.14
C ENDFUNCTION
D OUTPUT GetPi()
Line B — A function must send a value back to the place where it was called. It needs RETURN 3.14, not OUTPUT.
Question 4
A PROCEDURE Line()
B OUTPUT "-----"
C ENDFUNCTION
D CALL Line()
E CALL Line()
Line C — A procedure must finish with ENDPROCEDURE. ENDFUNCTION is only used to close a function.
Question 5
A PROCEDURE Hello()
B OUTPUT "Hello"
C ENDPROCEDURE
D Hello()
E CALL Hello()
Line D — A procedure is run using the keyword CALL. The line should be CALL Hello(), so the subroutine can be called as many times as needed.

Student with a class code? Join your class →