← IGCSE Computer Science Paper 2

Common mistakes when calling procedures and functions

A common error when SumSquare is a function. CALL is only for procedures. A function returns a value, so use it in an expression, in OUTPUT, or store it in a variable.

Understanding Common mistakes when calling procedures and functions in IGCSE Computer Science Paper 2

What it does: The function returns a value but nothing uses it. It should be output, stored in a variable or used in an expression. Only functions return values. A procedure used inside an expression is an error. A procedure gives nothing back, so it cannot be added to 10. CALL ShowScore() is the correct way to run it. Each subroutine needs its matching end. FUNCTION ends with ENDFUNCTION and PROCEDURE ends with ENDPROCEDURE. Missing it is a common error. The function definition is not closed. Adding ENDFUNCTION after the RETURN line marks the end of the function.

Common mistakes: Sq is a function, and CALL is only for procedures. A function returns a value, so its result must be stored or used. The line should be R ← Sq(5). A function call alone on a line throws away the value it returns, so nothing is shown. The result must be used, for example OUTPUT Sq(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 419–428) and word search (Modules 419–438).

Take this worksheet further — free with Cloodit

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

Learning
Duo
SumSquare is a FUNCTION that returns a number. Which line calls it correctly?
CALL SumSquare(2, 3)Total ← SumSquare(2, 3)
Matches
Answer ← ShowTotal(5) + 1
↓
ShowTotal is a procedure, so it returns no value. It cannot be used in an expression. Use CALL ShowTotal(5) on its own, or make it a function.
Applying
Meanings
Term
CALL SumSquare(2, 3)
Meaning
A common error when SumSquare is a function. CALL is only for procedures. A function returns a value, so use it in an expression, in OUTPUT, or store it in a variable.
Practice
FUNCTION SumSquare(A : INTEGER, B : INTEGER) RETURNS INTEGER
Testing
Gaps
ShowScore(5)
Check Answer
Spots
1DECLARE R : INTEGER
2CALL Sq(5)

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

The 'Moose' badge — Tundra Champion, 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. SumSquare is a FUNCTION that returns a number. Which line calls it correctly?
A. Total ← SumSquare(2, 3) ✓
B. CALL SumSquare(2, 3)
CALL is only for procedures. A function returns a value, so store it in a variable, use it in OUTPUT, or use it in an expression.
2. Greet is a PROCEDURE. Which line calls it correctly?
A. CALL Greet("Sam") ✓
B. Name ← Greet("Sam")
A procedure does not return a value, so it cannot be stored in a variable. Call it with CALL.
3. Double is a FUNCTION. What happens when you write Double(5) alone on a line?
A. The result is printed on the screen automatically
B. The result is thrown away and not used ✓
A function returns a value, but nothing happens to it unless you OUTPUT it, store it or use it in an expression.
4. Which line makes use of the value returned by the function Double?
A. Double(5)
B. OUTPUT Double(5) ✓
OUTPUT displays the returned value. A function call on its own line throws the result away.
5. PrintLine is a PROCEDURE. Which statement is true?
A. It does not return a value, so it cannot be used in an expression ✓
B. It returns a value, so X ← PrintLine() is fine
Only functions return values. A procedure used inside an expression is an error.

Match the Pairs

CALL SumSquare(2, 3) → Wrong when SumSquare is a function. CALL is only for procedures, so a function must be used in an expression, in OUTPUT or stored in a variable.
Total ← AddFive(4) + 1 → Correct use of a function call inside an expression. The returned value is used in the calculation and stored in Total.
A function call on a line by itself throws away the returned value, so the result is lost. → SumSquare(2, 3)
A procedure does not return a value, so it must be run with CALL and not used inside an expression. → CALL ShowTotal(5)
Answer ← ShowTotal(5) + 1 → ShowTotal is a procedure, so it returns no value. It cannot be used in an expression. Use CALL ShowTotal(5) on its own, or make it a function.
FUNCTION Double(N : INTEGER) RETURNS INTEGER RETURN N * 2 → The ENDFUNCTION statement is missing. Every function must finish with ENDFUNCTION, and every procedure with ENDPROCEDURE.

Key Term

CALL SumSquare(2, 3)
A common error when SumSquare is a function. CALL is only for procedures. A function returns a value, so use it in an expression, in OUTPUT, or store it in a variable.

Fill in the Blanks

1. CALL ShowScore(5)
Hint: Type the keyword that must start a statement calling a procedure. It is never used with a function.
2. Total ← SumSquare(2, 3)
Hint: Type the name of the function whose returned value is stored in the variable.
3. OUTPUT SumSquare(2, 3)
Hint: Type the keyword that displays the value a function returns, so the result is not thrown away.
4. PROCEDURE ShowScore(Score : INTEGER) OUTPUT Score ENDPROCEDURE
Hint: Type the keyword that closes a procedure definition.
5. FUNCTION Twice(N : INTEGER) RETURNS INTEGER RETURN N * 2 ENDFUNCTION
Hint: Type the keyword that closes a function definition.

Spot the Error

Question 1
A DECLARE R : INTEGER
B CALL Sq(5)
C OUTPUT R
D FUNCTION Sq(N) RETURNS INTEGER
E RETURN N * N
F ENDFUNCTION
Line B — Sq is a function, and CALL is only for procedures. A function returns a value, so its result must be stored or used. The line should be R ← Sq(5).
Question 2
A N ← 7
B Sq(N)
C FUNCTION Sq(N) RETURNS INTEGER
D RETURN N * N
E ENDFUNCTION
Line B — A function call alone on a line throws away the value it returns, so nothing is shown. The result must be used, for example OUTPUT Sq(N).
Question 3
A N ← 4
B Total ← Show(N)
C PROCEDURE Show(N : INTEGER)
D OUTPUT N * 2
E ENDPROCEDURE
Line B — Show is a procedure, so it does not return a value and cannot be used in an assignment. Procedures are run with CALL, so the line should be CALL Show(N).
Question 4
A PROCEDURE Cube(N) RETURNS REAL
B RETURN N * N * N
C ENDFUNCTION
D OUTPUT Cube(2)
Line A — A subroutine that returns a value is a function, not a procedure. The header should start with FUNCTION. A procedure never has a RETURNS type.
Question 5
A FUNCTION Sq(N) RETURNS INTEGER
B RETURN N * N
C ENDFUNCTION
D R ← CALL Sq(3)
E OUTPUT R
Line D — CALL must not be used with a function. A function is called inside an expression, so the line should be R ← Sq(3).

Student with a class code? Join your class →