← IGCSE Computer Science Paper 2

Defining a function with no parameters

Starts a function with no parameters: the name has no brackets, RETURNS gives the data type of the value sent back, and ENDFUNCTION closes the function.

Understanding Defining a function with no parameters in IGCSE Computer Science Paper 2

What it does: There are no parameters, so the name GetPi stands alone, followed directly by RETURNS REAL. The header names the function and its return type, RETURN sends back the REAL value 3.14, and ENDFUNCTION closes it. In Cambridge pseudocode a function with no parameters is written with no brackets after its name. Every FUNCTION must finish with ENDFUNCTION, just as a procedure finishes with ENDPROCEDURE.

Common mistakes: A function with no parameters is written without brackets after its name. It should be FUNCTION GetPi RETURNS REAL. The header must have the keyword RETURNS before the data type. It should be FUNCTION GetMax RETURNS INTEGER.

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 header correctly starts a function called GetPi that has no parameters and returns a REAL?
FUNCTION GetPi RETURNS REALFUNCTION GetPi() RETURNS REAL
Matches
FUNCTION GetPi() RETURNS REAL
↓
Empty brackets were added after the name. A function with no parameters is written without brackets, so it should be FUNCTION GetPi RETURNS REAL.
Applying
Meanings
Term
FUNCTION GetPi RETURNS REAL
Meaning
Starts a function with no parameters: the name has no brackets, RETURNS gives the data type of the value sent back, and ENDFUNCTION closes the function.
Practice
FUNCTION GetPi RETURNS REAL
Testing
Gaps
GetPi RETURNS REAL
Check Answer
Spots
1FUNCTION GetPi() RETURNS REAL
2 RETURN 3.14159

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

The 'Kangaroo Rat' badge — Speed Typer, 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 function called GetPi that has no parameters and returns a REAL?
A. FUNCTION GetPi RETURNS REAL ✓
B. FUNCTION GetPi() RETURNS REAL
In Cambridge pseudocode a function with no parameters is written with no brackets after its name.
2. What closes a function definition?
A. ENDFUNCTION ✓
B. ENDPROCEDURE
A function is closed with ENDFUNCTION. ENDPROCEDURE closes a procedure.
3. In FUNCTION GetPi RETURNS REAL, what does REAL tell us?
A. The data type of the value the function sends back ✓
B. The data type of a parameter passed into the function
The data type after RETURNS is the type of the returned value. GetPi has no parameters.
4. Which word must come between the function name and the data type?
A. RETURN
B. RETURNS ✓
The header uses RETURNS followed by the data type. RETURN (without the S) is the statement inside the function that sends the value back.
5. Which function definition is written correctly?
A. FUNCTION GetPi RETURNS REAL RETURN 3.14 ENDPROCEDURE
B. FUNCTION GetPi RETURNS REAL RETURN 3.14 ENDFUNCTION ✓
Every FUNCTION must be closed with ENDFUNCTION, and the body should contain a RETURN statement.

Match the Pairs

FUNCTION GetPi RETURNS REAL → Starts a function with no parameters that sends back a REAL value
ENDFUNCTION → Closes the function definition after its statements
A function with no parameters has no brackets after its name, then RETURNS and the data type → FUNCTION GetPi RETURNS REAL
A complete function with no parameters returns a value before ENDFUNCTION → FUNCTION GetPi RETURNS REAL RETURN 3.14 ENDFUNCTION
FUNCTION GetPi() RETURNS REAL → Empty brackets were added after the name. A function with no parameters is written without brackets, so it should be FUNCTION GetPi RETURNS REAL.
FUNCTION GetPi RETURN 3.14 ENDFUNCTION → The RETURNS keyword and data type are missing from the header. It should be FUNCTION GetPi RETURNS REAL.

Key Term

FUNCTION GetPi RETURNS REAL
Starts a function with no parameters: the name has no brackets, RETURNS gives the data type of the value sent back, and ENDFUNCTION closes the function.

Fill in the Blanks

1. FUNCTION GetPi RETURNS REAL RETURN 3.14159 ENDFUNCTION
Hint: Type the keyword that starts the definition of a function.
2. FUNCTION GetPi RETURNS REAL RETURN 3.14159 ENDFUNCTION
Hint: Type the keyword that comes before the data type of the value sent back.
3. FUNCTION IsOpen RETURNS BOOLEAN RETURN TRUE ENDFUNCTION
Hint: Type the data type of the value this function sends back.
4. FUNCTION GetLimit RETURNS INTEGER RETURN 100 ENDFUNCTION
Hint: Type the keyword that closes the function.
5. FUNCTION GetPi RETURNS REAL RETURN 3.14159 ENDFUNCTION
Hint: Type the keyword that sends the value back to the caller.

Spot the Error

Question 1
A FUNCTION GetPi() RETURNS REAL
B RETURN 3.14159
C ENDFUNCTION
Line A — A function with no parameters is written without brackets after its name. It should be FUNCTION GetPi RETURNS REAL.
Question 2
A FUNCTION GetMax INTEGER
B RETURN 100
C ENDFUNCTION
Line A — The header must have the keyword RETURNS before the data type. It should be FUNCTION GetMax RETURNS INTEGER.
Question 3
A FUNCTION GetTen RETURNS INTEGER
B Total ← 10
C RETURN Total
D ENDPROCEDURE
Line D — A function is closed with ENDFUNCTION, not ENDPROCEDURE. ENDPROCEDURE belongs to procedures.
Question 4
A FUNCTION GetName RETURNS STRING
B Name ← "Sam"
C OUTPUT Name
D ENDFUNCTION
Line C — A function must send its value back with RETURN. OUTPUT only displays it, so the line should be RETURN Name.
Question 5
A FUNCTION GetPi RETURNS REAL
B RETURN "3.14159"
C ENDFUNCTION
Line B — The function RETURNS REAL, so it must return a number. The quotes make it a STRING. It should be RETURN 3.14159.

Student with a class code? Join your class →