0984
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.
stable
Rare
Stable4%
Writing and calling procedures/functions with parameters is tested in Paper 2.
A real program may be hundreds or thousands of lines long. Writing it as one giant block of code would be hard to read, hard to test, hard to debug, and almost impossible to maintain. The solution is to break the program into named blocks that each do one specific job. These named blocks are called .
Sub-programs make code:
- Reusable: the same block can be called from many places, instead of being written out many times.
- Easier to read: a well-named sub-program tells the reader what it does without making them read its body.
- Easier to test: each sub-program can be tested on its own with chosen inputs.
- Easier to maintain: a bug in one sub-program is fixed in one place, and the fix immediately applies everywhere that sub-program is called.
There are two kinds of sub-program: and .
The key difference: a function returns a value; a procedure does not.