← IGCSE Computer Science Paper 2

The RETURN statement

RETURN followed by a value or expression sends that value back to where the function was called, e.g. RETURN Number1 * Number1. It also ends the function.

Understanding The RETURN statement in IGCSE Computer Science Paper 2

What it does: RETURN Num * 2 is the last statement before ENDFUNCTION, and it sends the result back to the caller. RETURN is followed directly by a value or expression. The data type is given in the RETURNS part of the function header, not after RETURN. Once RETURN runs, control goes back to where the function was called. The returned value replaces the call, so it can be stored in a variable on the left of the assignment arrow.

Common mistakes: RETURN must be followed by a value or expression. A bare RETURN sends nothing back to the call. It should be RETURN Result. OUTPUT only displays the value. It does not send it back to where the function was called, so Sq(5) has no value. The line should be RETURN N * N.

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
Which statement sends a value back to the place where a function was called?
RETURN TotalOUTPUT Total
Matches
FUNCTION Square(Number1 : INTEGER) RETURNS INTEGER OUTPUT Number1 * Number1 ENDFUNCTION
↓
The function uses OUTPUT instead of RETURN, so no value is sent back to the caller. It should be RETURN Number1 * Number1.
Applying
Meanings
Term
RETURN
Meaning
RETURN followed by a value or expression sends that value back to where the function was called, e.g. RETURN Number1 * Number1. It also ends the function.
Practice
FUNCTION Square(Number1 : INTEGER) RETURNS INTEGER
Testing
Gaps
Number1 * Number1
Check Answer
Spots
2 Result ← N * N
3 RETURN

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

The 'Owl' badge — Wise 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 statement sends a value back to the place where a function was called?
A. OUTPUT Total
B. RETURN Total ✓
RETURN sends the value back to the call. OUTPUT only displays it on screen and does not hand it back to the program.
2. Which function ends with a correct RETURN of an expression?
A. RETURN Number1 * Number1 ✓
B. RETURN INTEGER Number1 * Number1
RETURN is followed directly by a value or expression. The data type is given in the RETURNS part of the function header, not after RETURN.
3. Where does the RETURN statement normally go in a function?
A. At the very start, before the function header
B. As the last statement, just before ENDFUNCTION ✓
RETURN sits inside the function body, usually as its last statement before ENDFUNCTION.
4. A function has this line: RETURN Result. What does it return?
A. The value currently stored in the variable Result ✓
B. The word "Result" as text
RETURN with a variable name sends back the value held in that variable, not its name.
5. FUNCTION Double(N : INTEGER) RETURNS INTEGER has RETURN N * 2 on line 2 and OUTPUT "Done" on line 3. What happens when Double(5) is called?
A. It returns 10 and "Done" is never output ✓
B. It returns 10 and then outputs "Done"
RETURN ends the function straight away, so any lines after it are never run.

Match the Pairs

RETURN Number1 * Number1 → Works out the square of Number1 and sends that value back to where the function was called
RETURN Total → Sends the value stored in the variable Total back to the place where the function was called
A function ends with RETURN as its last statement, sending back its answer → FUNCTION Double(Num : INTEGER) RETURNS INTEGER RETURN Num * 2 ENDFUNCTION
RETURN ends the function, so any statement written after it in the same path never runs → RETURN Result OUTPUT "Done"
FUNCTION Square(Number1 : INTEGER) RETURNS INTEGER OUTPUT Number1 * Number1 ENDFUNCTION → The function uses OUTPUT instead of RETURN, so no value is sent back to the caller. It should be RETURN Number1 * Number1.
FUNCTION Add(A : INTEGER, B : INTEGER) RETURNS INTEGER RETURN ENDFUNCTION → RETURN has no value or expression after it, so nothing is sent back. It should be RETURN A + B.

Key Term

RETURN
RETURN followed by a value or expression sends that value back to where the function was called, e.g. RETURN Number1 * Number1. It also ends the function.

Fill in the Blanks

1. FUNCTION Sq(Number1 : REAL) RETURNS REAL RETURN Number1 * Number1 ENDFUNCTION
Hint: Type the keyword that sends the result back to where the function was called.
2. FUNCTION Sq(Number1 : REAL) RETURNS REAL RETURN Number1 * Number1 ENDFUNCTION
Hint: Type the operator that multiplies, so the returned expression squares the number.
3. Sum ← A + B RETURN Sum ENDFUNCTION
Hint: Type the variable that holds the value to send back.
4. Result ← Sq(5) OUTPUT Result
Hint: Type the variable that stores the value the function returned.
5. FUNCTION Pass(Mark : INTEGER) RETURNS BOOLEAN RETURN Mark >= 50 ENDFUNCTION
Hint: Type the comparison operator for 'greater than or equal to' so the returned expression gives TRUE or FALSE.

Spot the Error

Question 1
A FUNCTION Sq(N) RETURNS INTEGER
B Result ← N * N
C RETURN
D ENDFUNCTION
Line C — RETURN must be followed by a value or expression. A bare RETURN sends nothing back to the call. It should be RETURN Result.
Question 2
A FUNCTION Sq(N) RETURNS INTEGER
B OUTPUT N * N
C ENDFUNCTION
D OUTPUT Sq(5)
Line B — OUTPUT only displays the value. It does not send it back to where the function was called, so Sq(5) has no value. The line should be RETURN N * N.
Question 3
A PROCEDURE Half(N)
B RETURN N / 2
C ENDFUNCTION
Line A — Only a function can use RETURN to send a value back. A procedure does not return a value. The header should be FUNCTION Half(N) RETURNS REAL.
Question 4
A FUNCTION Pay(H) RETURNS REAL
B Total ← H * 12.5
C OUTPUT "Paid"
D RETURN H
E ENDFUNCTION
Line D — This returns the hours, not the pay that was worked out. The line should be RETURN Total so the calculated value goes back to the call.
Question 5
A FUNCTION Dbl(N) RETURNS INTEGER
B Answer ← N * 2
C RETURNS Answer
D ENDFUNCTION
E OUTPUT Dbl(4)
Line C — RETURNS belongs in the function header to give the data type. Inside the function the statement is RETURN Answer.

Student with a class code? Join your class →