← IGCSE Computer Science Paper 2

Pseudocode FUNCTION ... RETURNS ... RETURN ... ENDFUNCTION

Starts a function that takes a typed parameter and RETURNS a value of the stated type. RETURN sends the value back, ENDFUNCTION closes it, and you can call it inside an expression.

Understanding Pseudocode FUNCTION ... RETURNS ... RETURN ... ENDFUNCTION in IGCSE Computer Science Paper 2

What it does: This shows the full structure: header with parameter and return type, an indented RETURN of a calculated value, then ENDFUNCTION. Square(5) is replaced by the value it returns (25), so it can be added to 10 and stored in Total. A procedure cannot be used like this. RETURN sends the value back to the code that called the function. OUTPUT only displays it on the screen and sends nothing back. Every FUNCTION is closed with ENDFUNCTION. ENDPROCEDURE belongs to procedures. A function header must include RETURNS followed by the data type, for example FUNCTION Double(Num : INTEGER) RETURNS INTEGER.

Common mistakes: A parameter must be written as Name : TYPE. The colon is missing, so it should be FUNCTION Sq(N : INTEGER). The function header states the type with the keyword RETURNS. RETURN is only used inside the body to send a value back. It should be RETURNS REAL.

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 123–134) and word search (Modules 123–145).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which header correctly starts a Cambridge pseudocode function that takes a whole number and gives back a whole number?
FUNCTION Double(Num : INTEGER) RETURNS INTEGERFUNCTION Double(Num : INTEGER) INTEGER
Matches
FUNCTION Double(Num : INTEGER) RETURN Num * 2 ENDFUNCTION
↓
The header is missing RETURNS INTEGER, so the type of value sent back is not stated
Applying
Meanings
Term
FUNCTION Name(Param : TYPE) RETURNS TYPE
Meaning
Starts a function that takes a typed parameter and RETURNS a value of the stated type. RETURN sends the value back, ENDFUNCTION closes it, and you can call it inside an expression.
Practice
FUNCTION Double(Num : INTEGER) RETURNS INTEGER
Testing
Gaps
Square(N : INTEGER) RETURNS INTEGER
Check Answer
Spots
1FUNCTION Sq(N INTEGER)
2 RETURNS INTEGER

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

The 'Gulper Eel' badge — Deep Streak, 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 header correctly starts a Cambridge pseudocode function that takes a whole number and gives back a whole number?
A. FUNCTION Double(Num : INTEGER) RETURNS INTEGER ✓
B. FUNCTION Double(Num : INTEGER) INTEGER
A function header must include RETURNS followed by the data type of the value it sends back.
2. Which line sends a calculated value back from a function called Square?
A. RETURN Num * Num ✓
B. OUTPUT Num * Num
RETURN sends the value back to the code that called the function. OUTPUT only displays it on the screen and sends nothing back.
3. How should a function definition be closed?
A. ENDPROCEDURE
B. ENDFUNCTION ✓
Every FUNCTION is closed with ENDFUNCTION. ENDPROCEDURE belongs to procedures.
4. Which statement about functions is true?
A. A function never sends a value back
B. A function sends a value back using RETURN ✓
The key difference between a function and a procedure is that a function returns a value.
5. Which is the correct way to use the function Double inside an expression?
A. Total ← Double(5) + 1 ✓
B. CALL Double(5) + 1
A function call can be used as a value inside an expression. CALL is used for procedures and cannot be part of a calculation.

Match the Pairs

FUNCTION Double(Num : INTEGER) RETURNS INTEGER → Starts a function called Double that takes an integer parameter Num and will send back an integer value
RETURN Num * 2 → Sends the calculated value Num multiplied by 2 back to the part of the program that called the function
A function is closed with ENDFUNCTION after its RETURN line, and the function body is indented → FUNCTION Square(N : INTEGER) RETURNS INTEGER RETURN N * N ENDFUNCTION
A function call can be used inside an expression because it gives back a value → Total ← Square(5) + 10
FUNCTION Double(Num : INTEGER) RETURN Num * 2 ENDFUNCTION → The header is missing RETURNS INTEGER, so the type of value sent back is not stated
FUNCTION Double(Num : INTEGER) RETURNS INTEGER OUTPUT Num * 2 ENDFUNCTION → OUTPUT is used instead of RETURN, so the value is only displayed and not sent back to the caller

Key Term

FUNCTION Name(Param : TYPE) RETURNS TYPE
Starts a function that takes a typed parameter and RETURNS a value of the stated type. RETURN sends the value back, ENDFUNCTION closes it, and you can call it inside an expression.

Fill in the Blanks

1. FUNCTION Square(N : INTEGER) RETURNS INTEGER RETURN N * N ENDFUNCTION
Hint: Type the keyword that starts a subroutine which sends a value back.
2. FUNCTION Half(N : INTEGER) RETURNS REAL RETURN N / 2 ENDFUNCTION
Hint: Type the data type of the parameter N, which holds a whole number.
3. FUNCTION Cube(N : INTEGER) RETURNS INTEGER RETURN N * N * N ENDFUNCTION
Hint: Type the header keyword that states the data type of the value sent back.
4. FUNCTION AddVAT(P : REAL) RETURNS REAL RETURN P * 1.2 ENDFUNCTION
Hint: Type the keyword that sends the calculated value back to the caller.
5. INPUT Price Total ← AddVAT(Price) + 5 OUTPUT Total
Hint: Type the variable that was just input and is passed to the function as its argument.

Spot the Error

Question 1
A FUNCTION Sq(N INTEGER)
B RETURNS INTEGER
C RETURN N * N
D ENDFUNCTION
E OUTPUT Sq(3)
Line A — A parameter must be written as Name : TYPE. The colon is missing, so it should be FUNCTION Sq(N : INTEGER).
Question 2
A FUNCTION Half(N : REAL)
B RETURN REAL
C RETURN N / 2
D ENDFUNCTION
Line B — The function header states the type with the keyword RETURNS. RETURN is only used inside the body to send a value back. It should be RETURNS REAL.
Question 3
A FUNCTION Cube(N : INTEGER)
B RETURNS STRING
C RETURN N * N * N
D ENDFUNCTION
E OUTPUT Cube(3)
Line B — The function returns the result of a multiplication, which is a number. The RETURNS type must match the value returned, so it should be RETURNS INTEGER.
Question 4
A PROCEDURE Tax(P : REAL)
B RETURNS REAL
C RETURN P * 0.2
D ENDFUNCTION
Line A — This subroutine returns a value and ends with ENDFUNCTION, so it must start with FUNCTION, not PROCEDURE. A procedure does not return a value.
Question 5
A FUNCTION Cost(P : REAL)
B RETURNS REAL
C OUTPUT P * 1.2
D ENDFUNCTION
E OUTPUT Cost(10)
Line C — OUTPUT only displays the value. It does not send it back to the caller. A function must use RETURN P * 1.2 to give its result back.

Student with a class code? Join your class →