← IGCSE Computer Science Paper 2

Difference between a procedure and a function

Only a function has RETURNS: it gives back a value used where it is called. A procedure returns nothing and is run on its own with CALL.

Understanding Difference between a procedure and a function in IGCSE Computer Science Paper 2

What it does: The call Total(3, 4) is replaced by the value it returns, so that value can be stored in Cost. A function returns a value to the place where it was called. A procedure does not return anything. A procedure is run as its own statement using CALL. It has no value to store in a variable. A function call is used inside an expression, such as an assignment. CALL is only for procedures.

Common mistakes: A function must give its value back to the place it was called, so it needs RETURN Result. OUTPUT only displays the value and returns nothing. A procedure starts with PROCEDURE, so it must finish with ENDPROCEDURE. ENDFUNCTION is only used to close a function.

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 399–408) 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 one gives back a value that can be used where it is called?
A procedureA function
Matches
CALL Total(3, 4)
↓
Total is a function, and CALL is only for procedures. The returned value is lost. Write Answer ← Total(3, 4) or OUTPUT Total(3, 4).
Applying
Meanings
Term
RETURNS
Meaning
Only a function has RETURNS: it gives back a value used where it is called. A procedure returns nothing and is run on its own with CALL.
Practice
PROCEDURE ShowLine()
Testing
Gaps
FUNCTION Twice(N : INTEGER) INTEGER
Check Answer
Spots
2 Result ← 5 + 3
3 OUTPUT Result

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

The 'Seahorse' badge — Range Rider, 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 one gives back a value that can be used where it is called?
A. A function ✓
B. A procedure
A function returns a value to the place where it was called. A procedure does not return anything.
2. Which header is a function?
A. FUNCTION Total(a, b) RETURNS INTEGER ✓
B. PROCEDURE Total(a, b) RETURNS INTEGER
Only a function has RETURNS in its header. A procedure header never has RETURNS.
3. How do you run a procedure called DrawLine?
A. total ← CALL DrawLine()
B. CALL DrawLine() ✓
A procedure is run as its own statement using CALL. It has no value to store in a variable.
4. Which statement uses a function correctly?
A. total ← AddUp(4, 5) ✓
B. CALL AddUp(4, 5)
A function call is used inside an expression, such as an assignment. CALL is only for procedures.
5. Which subroutine would you use to draw a line of 20 stars on the screen and return nothing?
A. A function
B. A procedure ✓
Drawing a line just does a job. No value needs to come back, so a procedure is the right choice.

Match the Pairs

FUNCTION AddUp(X : INTEGER) RETURNS INTEGER → A function header: RETURNS gives the data type of the value the function sends back.
PROCEDURE DrawLine() → A procedure header with no RETURNS part, because a procedure gives nothing back.
A function's returned value is used where it is called, for example stored in a variable → Cost ← Total(3, 4)
A procedure is called as its own statement using CALL → CALL DrawLine()
CALL Total(3, 4) → Total is a function, and CALL is only for procedures. The returned value is lost. Write Answer ← Total(3, 4) or OUTPUT Total(3, 4).
Result ← DrawLine() → DrawLine is a procedure and returns nothing, so there is no value to store. It should be run with CALL DrawLine().

Key Term

RETURNS
Only a function has RETURNS: it gives back a value used where it is called. A procedure returns nothing and is run on its own with CALL.

Fill in the Blanks

1. FUNCTION Twice(N : INTEGER) RETURNS INTEGER
Hint: Type the keyword in a function header that states the data type of the value given back.
2. CALL DrawLine(5)
Hint: Type the keyword used to run a procedure as its own statement.
3. FUNCTION Twice(N : INTEGER) RETURNS INTEGER RETURN N * 2 ENDFUNCTION
Hint: Type the statement inside a function that sends a value back to where it was called.
4. PROCEDURE DrawLine(Size : INTEGER) OUTPUT "-----" ENDPROCEDURE
Hint: Type the keyword that starts a subroutine that returns nothing.
5. Answer ← Twice(4) OUTPUT Answer
Hint: Type the assignment symbol that stores the value returned by the function call in a variable.

Spot the Error

Question 1
A FUNCTION Sum() RETURNS INTEGER
B Result ← 5 + 3
C OUTPUT Result
D ENDFUNCTION
Line C — A function must give its value back to the place it was called, so it needs RETURN Result. OUTPUT only displays the value and returns nothing.
Question 2
A PROCEDURE DrawLine()
B OUTPUT "----------"
C ENDFUNCTION
D CALL DrawLine()
Line C — A procedure starts with PROCEDURE, so it must finish with ENDPROCEDURE. ENDFUNCTION is only used to close a function.
Question 3
A PROCEDURE Hello()
B OUTPUT "Hi"
C ENDPROCEDURE
D Hello()
Line D — A procedure is run as its own statement using CALL. The line should be CALL Hello().
Question 4
A FUNCTION Pi() RETURNS REAL
B RETURNS 3.14
C ENDFUNCTION
D OUTPUT Pi()
Line B — RETURNS belongs in the function header to give the data type. Inside the function the keyword that sends a value back is RETURN 3.14.
Question 5
A PROCEDURE Show(N : INTEGER)
B RETURN N * 2
C ENDPROCEDURE
Line B — A procedure returns nothing, so it cannot use RETURN. It should display the value with OUTPUT N * 2.

Student with a class code? Join your class →