Functions and Procedures
This GCSE computing lesson explores Functions and Procedures in Programming. Students create reusable subprograms, pass parameters, return values and explain how functions and procedures support decomposition, testing and maintainability. It supports KS4 classroom teaching, independent study and exam revision using clear, subject-specific vocabulary.
Functions and Procedures
This GCSE computing lesson explores Functions and Procedures in Programming. Students create reusable subprograms, pass parameters, return values and explain how functions and procedures support decomposition, testing and maintainability. It supports KS4 classroom teaching, independent study and exam revision using clear, subject-specific vocabulary.
Functions, KS4 Computer Science, GCSE Computer Science, Subroutines, Functions, Procedures, Parameters, Return Values, Scope, Local Variables, Global Variables, Code Reusability, Modular Programming, MCQs, Open Questions, Polls, Emoji Polls, Exit Tickets
Learning goal
I can explain the difference between functions and procedures, and use them to organise code, reduce repetition, and break problems into manageable parts.
This item has no instructions
One word or phrase you link with subroutines
Use this to surface prior knowledge such as reuse, blocks, functions, commands, steps, or code. Invite students to explain any familiar terms that appear often.
Why use subroutines?
Subroutines are named blocks of code that carry out a task.
They help programmers to:
avoid writing the same code again and again
split a large problem into smaller parts
make code easier to read
test and debug one part at a time
At this point, treat 'subroutine' as the umbrella term that includes both functions and procedures. Students often know the idea from block-based programming even if the vocabulary is new.
One program, smaller parts
Instead of one long script, a program can be organised into short subroutines.
Each subroutine has one clear job, such as calculating a total, checking an input, or displaying a message.
This item has no instructions
Defining and calling
A subroutine must usually be defined before it can be used.
Define: write the instructions and give the subroutine a name
Call: use its name to run it
A subroutine can be called many times from different places in a program
You may want to give a tiny pseudocode example aloud, such as `displayMenu()` being defined once and called wherever needed.
What is the main purpose of calling a subroutine?
To run it
To rename it
To delete it
To store it
Checks defining versus calling after slides 2 to 4. 'Rename' and 'store' target students who confuse naming code with using it.
Complete the summary
A subroutine is a named block of code that carries out a task. Programmers define it by writing its instructions and giving it a name. They call it when they want to run that code again in the program.
The three blanks are key vocabulary from the first teaching block and each position is fixed by meaning.
Two types of subroutine
The two main types are functions and procedures.
A function returns a value
A procedure performs an action
Both can help organise code
The key difference is what happens when the subroutine finishes
Keep the distinction simple here: return value versus action only. Save parameters and variables for later slides.
What is a function?
A function is a subroutine that sends a value back to the code that called it.
That returned value can be stored in a variable, printed, or used in a calculation.
Stress that the function itself does not have to display anything. Its main job is to produce and return a result.
Function example
A function could calculate the area of a rectangle.
input: length and width
process: multiply them
output: the area as a returned value
A simple pseudocode example you can mention: `function area(length, width) return length * width`. Then show how `result = area(5, 3)` uses the returned value.
What is a procedure?
A procedure is a subroutine that carries out instructions without returning a value.
It is often used for actions such as displaying output, updating data, or playing a sound.
Students may confuse 'no return value' with 'does nothing useful'. Emphasise that procedures are useful when the goal is the action itself.
Procedure example
A procedure could display a greeting on the screen.
input: a name
process: join the text together
action: print the message
You could say aloud: `procedure greet(name)` then `print("Hello " + name)`. Contrast this with a function that returns the greeting instead of printing it.
Function or procedure?
Use a function when the program needs a result back.
Use a procedure when the program mainly needs something to happen.
calculate a discount → function
print a receipt → procedure
check both the action and the output needed
The final bullet helps avoid over-simplification: in some languages or designs, either can be used, but the lesson should reinforce the core distinction.
Which subroutine should return a value?
Procedure
Global
Function
Parameter
Tests the core distinction after slides 5 to 10.
For which task would you choose a procedure?
Calculate area
Print greeting
Work out VAT
Find average
This item has no instructions
Why is printing a greeting a procedure?
Expected elements: a procedure is best when the aim is the action itself, not sending a result back. A strong answer may mention displaying output, printing a message, or carrying out instructions without a return value.
Parameters and arguments
Subroutines often need information to work with.
Parameters are the variables named in the subroutine definition
Arguments are the actual values given when the subroutine is called
They let one subroutine work with different data each time
A clear verbal example: in `function area(length, width)`, `length` and `width` are parameters. In `area(5, 3)`, `5` and `3` are arguments.
Why parameters matter
Without parameters, programmers may need many similar subroutines.
With parameters, one subroutine can be reused for different inputs, such as different prices, names, or measurements.
Link this directly to reducing repetition. One `calculateVAT(price)` is better than separate code for every product.
Return values
A return value is the result sent back by a function.
it can be stored in a variable
it can be used in another calculation
it can be passed into another subroutine
procedures do not return a value
If useful, mention that some languages have special cases, but for GCSE-level pseudocode the clean distinction is enough.
From input to output
arguments → parameters → processing → return value
This pattern explains how many functions work.
The function receives data, uses it inside the subroutine, then returns a result to the main program.
Use this as a process summary slide. You can narrate a full example such as `square(4)` producing `16`.
In area(5, 3), what are 5 and 3?
Parameters
Arguments
Globals
Returns
Checks parameter versus argument after slides 11 to 14.
Complete the process
In a function, arguments are the values given when it is called. They match the parameters in the definition. After processing, the function sends back a return value to the main program.
Echoes the wording from slides 11, 13, and 14.
Local variables
A local variable is created inside a subroutine.
it is used only within that subroutine
other parts of the program cannot normally use it directly
this helps keep tasks separate and reduces accidental errors
Students often think every variable is available everywhere. Stress scope: local means limited to that subroutine.
Global variables
A global variable is created outside subroutines and can be used in more than one part of the program.
This can be useful, but changes in one place can affect the whole program.
Avoid making globals sound 'forbidden'. The key point is that they are shared and must be handled carefully.
Local and global compared
Local: limited to one subroutine
Global: shared across the program
Local variables are often safer for temporary values
Global variables can make bugs harder to trace
A good example is a local `total` inside a function versus a global `username` or `score` used in several places.
Which variable is limited to one subroutine?
Argument
Return value
Global variable
Local variable
Tests scope after slides 15 to 17.
Why can global variables cause bugs?
Expected elements: global variables are shared across the program, so a change in one place can affect other parts. This can make bugs harder to trace. Local variables are safer for temporary values inside one subroutine.
Readable code
Subroutines make code easier to read because each part has a clear name and purpose.
A call such as `calculateTotal()` is easier to understand than repeating the same steps in many places.
Highlight that good names matter. A poorly named subroutine does less to improve readability.
Reusable code
A subroutine can be written once and used many times.
saves time
reduces repeated code
makes updates easier because one change fixes every use
This is a strong place to introduce the term 'DRY' verbally if you wish, but keep it off-slide unless your class already uses it.
Easier debugging
When code is split into subroutines, bugs are easier to find.
test one subroutine at a time
check inputs and outputs more clearly
fix a small section without searching the whole program
You can connect this to unit-style thinking without naming formal testing methods if that is beyond the class.
Breaking problems down
Large programming tasks become easier when they are divided into smaller jobs.
Problem → subroutines for each task → complete program
This is one way programmers manage complexity.
Make the explicit link to decomposition, but keep the lesson rooted in programming practice rather than broader theory.
How do subroutines help with debugging?
Hide all errors
Test one part
Remove all loops
Rename variables
Checks the final benefits block after slides 18 to 21.
Complete the summary
Subroutines make code more readable because each part has a clear purpose. They are also reusable because one subroutine can be used many times. This also helps with debugging because programmers can test one small section at a time.
Uses the key terms from slides 18 to 20.
How much more confident are you now with functions and proceedures in programming?
This item has no instructions
Glossary
subroutine - a named block of code that carries out a task
function - a subroutine that returns a value
procedure - a subroutine that performs an action without returning a value
define - to write a subroutine and give it a name
call - to run a subroutine by using its name
parameter - a variable named in a subroutine definition
argument - the actual value passed into a subroutine when it is called
This item has no instructions
Glossary
return value - the result sent back by a function
local variable - a variable that can be used only inside the subroutine where it is created
global variable - a variable created outside subroutines that can be used in different parts of a program
readable code - code that is easy for people to understand
reusable code - code that can be used again in different places
debug - to find and fix errors in a program
decomposition - breaking a large problem into smaller parts
This item has no instructions