← IGCSE Computer Science Paper 2

Choosing a procedure or a function for a task

Use a FUNCTION when a task produces one value the program needs, such as an area; use a PROCEDURE when it only does something, such as OUTPUT a menu.

Understanding Choosing a procedure or a function for a task in IGCSE Computer Science Paper 2

What it does: The call to the function is used in an assignment because the function returns a value that is stored in Area. Displaying a menu is an action, not a value the program needs. Actions like this are written as procedures. Functions return a value with RETURN. Procedures do not return a value. Showing a menu only does something. Calculating a total gives one value back, which suits a function. A good justification uses 'because' and links the choice to a value being returned. Returning the value lets the program store it or use it in other calculations. Outputting it only shows it on screen.

Common mistakes: Area produces one value the program needs, so it is a FUNCTION. A FUNCTION must be closed with ENDFUNCTION, not ENDPROCEDURE. Showing a menu only does something, so it is a PROCEDURE. A procedure displays with OUTPUT and does not RETURN a value. The line should be OUTPUT "1. Play".

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
A subroutine works out the area of a rectangle and the program uses that number later. Which should you write?
A function, because it produces one value that the program needsA procedure, because it produces one value that the program needs
Matches
PROCEDURE CalcArea(L, W) RETURN L * W ENDPROCEDURE
↓
A procedure cannot return a value. The task produces one value the program needs, so it should be a FUNCTION with RETURNS and ENDFUNCTION.
Applying
Meanings
Term
FUNCTION
Meaning
Use a FUNCTION when a task produces one value the program needs, such as an area; use a PROCEDURE when it only does something, such as OUTPUT a menu.
Practice
// Procedure because it only displays
Testing
Gaps
ShowMenu()
Check Answer
Spots
2 RETURN S * S
3ENDPROCEDURE

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

The 'Chambered Nautilus' badge — File Explorer, 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. A subroutine works out the area of a rectangle and the program uses that number later. Which should you write?
A. A procedure, because it produces one value that the program needs
B. A function, because it produces one value that the program needs ✓
The area is a single value used later in the program, so a function RETURNs it. A procedure does not return a value.
2. A subroutine only displays a menu with OUTPUT and gives nothing back. Which should you write?
A. A procedure, because it only does something ✓
B. A function, because it only does something
Displaying a menu is an action, not a value the program needs. Actions like this are written as procedures.
3. Which statement is correct?
A. A function uses RETURN to send a value back to the line that called it ✓
B. A procedure uses RETURN to send a value back to the line that called it
Functions return a value with RETURN. Procedures do not return a value.
4. Which task suits a function?
A. Calculating the area of a circle from its radius ✓
B. Printing a welcome menu on the screen
The area is one value the program can store or use. Printing the menu is just an action, so it suits a procedure.
5. Which task suits a procedure?
A. Calculating the total price of items in a basket
B. Using OUTPUT to show a list of menu options ✓
Showing a menu only does something. Calculating a total gives one value back, which suits a function.

Match the Pairs

FUNCTION CalcArea(L : INTEGER, W : INTEGER) RETURNS INTEGER → Use a function because the task produces one value, the area, that the program needs.
PROCEDURE ShowMenu() → Use a procedure because the task only does something, such as displaying a menu, and gives no value back.
A function returns a value to the program, so the result can be stored in a variable. → Area ← CalcArea(5, 3)
A procedure only carries out actions such as OUTPUT, so it is run with its own CALL statement. → CALL ShowMenu()
PROCEDURE CalcArea(L, W) RETURN L * W ENDPROCEDURE → A procedure cannot return a value. The task produces one value the program needs, so it should be a FUNCTION with RETURNS and ENDFUNCTION.
FUNCTION ShowMenu() OUTPUT "1. Play" ENDFUNCTION → Displaying a menu only does something and returns no value, so it should be a PROCEDURE and not a FUNCTION.

Key Term

FUNCTION
Use a FUNCTION when a task produces one value the program needs, such as an area; use a PROCEDURE when it only does something, such as OUTPUT a menu.

Fill in the Blanks

1. PROCEDURE ShowMenu() OUTPUT "1. Play" ENDPROCEDURE
Hint: Type the keyword for a subroutine that only does something, such as displaying a menu, and gives no value back.
2. FUNCTION Area(L : INTEGER) RETURNS INTEGER RETURN L * L ENDFUNCTION
Hint: Type the keyword that states which data type the function sends back.
3. FUNCTION Area(L, W) RETURNS INTEGER RETURN L * W ENDFUNCTION
Hint: Type the keyword that sends the calculated value back to the caller instead of displaying it.
4. CALL ShowMenu() area ← Area(4, 5)
Hint: Type the keyword used to run a procedure as a statement on its own line.
5. area ← Area(3, 6) OUTPUT area
Hint: Type the assignment symbol that stores the value the function returns in a variable.

Spot the Error

Question 1
A FUNCTION Area(S) RETURNS REAL
B RETURN S * S
C ENDPROCEDURE
D OUTPUT Area(4)
Line C — Area produces one value the program needs, so it is a FUNCTION. A FUNCTION must be closed with ENDFUNCTION, not ENDPROCEDURE.
Question 2
A PROCEDURE ShowMenu()
B RETURN "1. Play"
C OUTPUT "2. Quit"
D ENDPROCEDURE
Line B — Showing a menu only does something, so it is a PROCEDURE. A procedure displays with OUTPUT and does not RETURN a value. The line should be OUTPUT "1. Play".
Question 3
A FUNCTION Area(S) RETURNS REAL
B RETURN S * S
C ENDFUNCTION
D CALL Area(5)
E OUTPUT Total
Line D — A function returns a value, so the call must be used in an expression or stored in a variable. CALL on its own throws the area away. It should be Total ← Area(5).
Question 4
A FUNCTION Perim(S) RETURNS REAL
B OUTPUT S * 4
C ENDFUNCTION
D OUTPUT Perim(3)
Line B — A function must RETURN its value so the program can use it. OUTPUT only displays it and gives nothing back. The line should be RETURN S * 4.
Question 5
A PROCEDURE ShowMenu()
B OUTPUT "1. Play"
C ENDPROCEDURE
D ShowMenu()
Line D — A procedure produces no value, so it is run with a CALL statement. Writing just the name is not a valid call. It should be CALL ShowMenu().

Student with a class code? Join your class →