Procedures, functions and maintainable programs Cambridge IGCSE Computer Science revision
Not started
Learn it
In plain words
As programs grow, the same few lines turn up again and again. Sooner than copy them out, you give them a name and call them by that name whenever they are needed. A named block of code like this is a procedure or a function.
The difference between the two is small but important: a function hands a value back.
6 things to know
- A procedure is a named block of code that carries out a task. It is run with CALL: for example, CALL ShowMenu.
- A function is a named block of code that carries out a task and returns a value. It is used inside an expression: Area ← RectangleArea(4, 5).
- A parameter is a value passed into a procedure or function when it is called, so that the same code can work on different data.
- A local variable is declared inside a procedure or function and can only be used there. A global variable is declared in the main program and can be used anywhere.
- A program is maintainable when someone else can read it and change it. That means meaningful identifiers for variables, constants, arrays, procedures and functions.
- It also means comments that explain what the code does, and procedures and functions that keep each task in one place.
Worked example
A function is defined as FUNCTION Double(Number : INTEGER) RETURNS INTEGER, and its body is RETURN Number * 2. What does OUTPUT Double(7) + 1 display?
- Double is called with the parameter 7.
- Inside the function, Number is 7, so it returns 7 × 2 = 14.
- The expression becomes 14 + 1, so 15 is displayed.
Tips and tricks
- A function returns a value and a procedure does not. If the question says "returns", it is a function.
- Use local variables where you can. A global variable can be changed from anywhere, which makes errors hard to track down.
It lands in your notebook with its questions as flashcards.
Procedures, functions and maintainable programs: 6 questions and answers
These are the quiz’s questions. Do the quiz first, then come back here for the ones that got you.
What is the difference between a function and a procedure?
Both are named blocks of code.
What is a parameter?
It lets the same code work with different data.
Where can a local variable be used?
Outside that block it does not exist.
Which keyword runs a procedure?
For example, CALL DrawLine(10).
Which of these makes a program easier to maintain?
Other programmers can then follow what the code does.
A function body is RETURN Length * Width. It is called as Area(3, 6). What does it return?
3 × 6 = 18.
Quiz
6 questions
Tap an answer and you’ll see straight away whether it’s right, and why.
Worksheet
3 questions, 7 marks. Write your answers on paper, then check them.
Procedures, functions and maintainable programs
Cambridge IGCSE Computer Science 0478 · 7 marks · papermunch.org
Name ______________________________ Date ______________
Describe the difference between a procedure and a function.[2]
Show answerHide answer
Both are named blocks of code that carry out a task. A function returns a value to the code that called it, and a procedure does not.
Give three ways of making a program easier to maintain.[3]
Show answerHide answer
Use meaningful identifiers. Add comments to explain the code. Use procedures and functions.
Describe the difference between a local variable and a global variable.[2]
Show answerHide answer
A local variable can only be used inside the procedure or function where it is declared. A global variable can be used anywhere in the program.
Answers: Procedures, functions and maintainable programs
- 1. Both are named blocks of code that carry out a task. A function returns a value to the code that called it, and a procedure does not.
- 2. Use meaningful identifiers. Add comments to explain the code. Use procedures and functions.
- 3. A local variable can only be used inside the procedure or function where it is declared. A global variable can be used anywhere in the program.



