Procedures and Functions
Programming · 4 question types
Exam Frequency Analysis
Past paper frequency (2018 to 2024)
This topic accounts for approximately 4% of your exam marks.
Writing and calling procedures/functions with parameters is tested in Paper 2.
A procedure is a named block of code that performs a task without returning a value. It is invoked using the
CALLkeyword.
Defining a procedure
A procedure with no parameters:
PROCEDURE ProcedureName
// statements that do the work
ENDPROCEDURE
A procedure with (values passed in):
PROCEDURE ProcedureName(Param1 : TYPE, Param2 : TYPE, ...)
// statements that use the parameters
ENDPROCEDURE
Each parameter is named and given a data type, so the procedure knows what kind of value to expect.
Calling a procedure
Procedures are run using the CALL keyword:
CALL ProcedureName
CALL ProcedureName(Value1, Value2)
The values in brackets are called . Each argument is matched in order to the corresponding parameter in the procedure's definition.
When to use a procedure
Choose a procedure when the sub-program's job is to do something rather than to compute and return something:
- Show a menu on screen.
- Save data to a file.
- Display a report.
- Reset all the variables to a known starting state.