← IGCSE Computer Science Paper 2

Where procedures and functions are defined

Write procedures and functions at the start of the code, before the main program. The main program comes after and holds the CALL statements and function calls that use them.

Understanding Where procedures and functions are defined in IGCSE Computer Science Paper 2

What it does: The procedure definition is at the top and the CALL statement is in the main program below it. Subroutines are defined first. The main program comes after and calls them. Procedures and functions are defined at the start of the code. Moving the CALL after ENDPROCEDURE fixes it.

Common mistakes: A procedure definition must finish with ENDPROCEDURE, not ENDFUNCTION. The definition is written first and then the main program calls it. CALL is only used for procedures. A function is called inside an expression or an OUTPUT statement, so the main program line should be OUTPUT Rate().

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 409–418) and word search (Modules 399–418).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Where should a procedure or function be defined in a Cambridge IGCSE program?
At the end, after the main programAt the start, before the main program
Matches
CALL ShowMenu() PROCEDURE ShowMenu() OUTPUT "1. Play" ENDPROCEDURE
↓
The CALL is placed before the procedure is defined. The definition must come first, then the main program with the CALL.
Applying
Meanings
Term
Define then call
Meaning
Write procedures and functions at the start of the code, before the main program. The main program comes after and holds the CALL statements and function calls that use them.
Practice
PROCEDURE ShowWelcome()
Testing
Gaps
Hello()
Check Answer
Spots
2 OUTPUT "1. Play"
3ENDFUNCTION

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

The 'Lion's Mane Jellyfish' badge — Set Operator, 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. Where should a procedure or function be defined in a Cambridge IGCSE program?
A. At the start, before the main program ✓
B. At the end, after the main program
Subroutines are defined first. The main program comes after and calls them.
2. Which layout is correct for a short program?
A. CALL Greet(), then PROCEDURE Greet() ... ENDPROCEDURE
B. PROCEDURE Greet() ... ENDPROCEDURE, then CALL Greet() ✓
The definition comes first. The CALL is in the main program, which comes after the definition.
3. Where do the CALL statements and function calls go?
A. Before the definitions, at the top of the code
B. In the main program, after the definitions ✓
The main program holds the calls. It sits below the definitions so the subroutines already exist when they are used.
4. Which part of a program comes first?
A. The subroutine definitions ✓
B. The main program statements
Definitions first, then the main program.
5. Which statement about the main program is true?
A. It comes after the definitions and uses them ✓
B. It comes before the definitions and defines them
The main program does not define subroutines. It calls the ones written above it.

Match the Pairs

PROCEDURE ShowMenu() OUTPUT "1. Play" ENDPROCEDURE CALL ShowMenu() → The procedure is defined first. The CALL line comes after it, in the main program.
FUNCTION Double(n : INTEGER) RETURNS INTEGER RETURN n * 2 ENDFUNCTION OUTPUT Double(4) → The function is defined at the start. The main program after it uses the function call.
Definitions come first in a short program, then the main program with the calls comes after them. → PROCEDURE Greet() OUTPUT "Hi" ENDPROCEDURE CALL Greet()
The main program holds the calls, so a function call such as one in an assignment goes after the definition. → FUNCTION Square(n : INTEGER) RETURNS INTEGER RETURN n * n ENDFUNCTION result <- Square(5)
CALL ShowMenu() PROCEDURE ShowMenu() OUTPUT "1. Play" ENDPROCEDURE → The CALL is placed before the procedure is defined. The definition must come first, then the main program with the CALL.
OUTPUT Double(4) FUNCTION Double(n : INTEGER) RETURNS INTEGER RETURN n * 2 ENDFUNCTION → The main program statement that calls the function is written before the function definition. The function should be defined first.

Key Term

Define then call
Write procedures and functions at the start of the code, before the main program. The main program comes after and holds the CALL statements and function calls that use them.

Fill in the Blanks

1. PROCEDURE Hello() OUTPUT "Hi" ENDPROCEDURE
Hint: Type the keyword that starts a procedure definition at the top of the code.
2. ENDPROCEDURE // Main program CALL Hello()
Hint: Type the keyword the main program uses to run a procedure that was defined above.
3. FUNCTION Double(N : INTEGER) RETURNS INTEGER RETURN N * 2 ENDFUNCTION
Hint: Type the keyword that sends a value back from the function definition.
4. ENDFUNCTION // Main program Answer ← Double(5)
Hint: Type the assignment operator that stores the function result in a variable in the main program.
5. PROCEDURE Hello() ENDPROCEDURE CALL Hello()
Hint: Type the name of the procedure defined above, so the main program can call it.

Spot the Error

Question 1
A PROCEDURE ShowMenu()
B OUTPUT "1. Play"
C ENDFUNCTION
D CALL ShowMenu()
Line C — A procedure definition must finish with ENDPROCEDURE, not ENDFUNCTION. The definition is written first and then the main program calls it.
Question 2
A FUNCTION Rate() RETURNS REAL
B RETURN 0.2
C ENDFUNCTION
D CALL Rate()
Line D — CALL is only used for procedures. A function is called inside an expression or an OUTPUT statement, so the main program line should be OUTPUT Rate().
Question 3
A // Definitions
B FUNCTION Beep()
C OUTPUT "Beep"
D ENDPROCEDURE
E // Main program
F CALL Beep()
Line B — Beep is a procedure because it does not return a value and ends with ENDPROCEDURE. The header must start with PROCEDURE, not FUNCTION.
Question 4
A FUNCTION GetName() RETURNS STRING
B Name ← "Sam"
C OUTPUT Name
D ENDFUNCTION
Line C — A function must send its value back with RETURN. OUTPUT only displays the value, so the line should be RETURN Name.
Question 5
A // Definitions come first
B FUNCTION GetPi() RETURN REAL
C RETURN 3.14
D ENDFUNCTION
E // Main program
F OUTPUT GetPi()
Line B — The function header must use the keyword RETURNS to state the return data type. It should be FUNCTION GetPi() RETURNS REAL.

Student with a class code? Join your class →