GCSE · Computer Science · AQA · Spec 8525

Procedures and functions

Nobody writes the same calculation fifty times. They write it once, give it a name and call it, and today you'll watch one of those calls happen, step by step.

Computer Science · Subroutines

Follow the call: into bonus and back again

Press Next and keep your eye on the highlighted line. Where does the program go? Where does each value land? What comes back?

Predict before you press Next: what will score hold when the program reaches OUTPUT?

1 SUBROUTINE bonus(points, level)
2 extra ← points * level
3 RETURN extra
4 ENDSUBROUTINE
5 score ← 50
6 score ← score + bonus(10, 3)
7 OUTPUT score

Variables

score=50

Output

 

Step 1: The program starts in the main program, at line 5. Lines 1 to 4 only define bonus. Defining a subroutine doesn't run it.

1 / 8

Watch the Variables panel: points, level and extra appear when bonus starts, and vanish when it returns.

Step 1 of 8: The program starts in the main program, at line 5. Lines 1 to 4 only define bonus. Defining a subroutine doesn't run it..

Exam line: Tell it in order: the call jumps to the subroutine, the arguments are passed to the parameters, RETURN sends a value back, and that value replaces the call.
Watch out: bonus is written first but runs second. Code inside a subroutine definition does nothing until the subroutine is called.

Computer Science · Subroutines

Procedure or function?

Pick a subroutine, then choose its kind. Each one is shown by its name and what its body does.

Still to sort

Function (0)

Returns a value to the code that called it.

Where the line is: RETURN sends a value back to the caller. Showing a value on screen with OUTPUT is not the same thing.

Procedure (0)

Carries out its task without returning a value.

Where the line is: A procedure can still take parameters and can still display things. It just sends nothing back.

5 of 5 still to sort.

Every subroutine is one or the other. Ask one question: does it send a value back to the caller with RETURN?

Computer Science · Debugging

Find the bug: where did the value go?

This program should work out how many seats a cinema screen has (5 rows of 8 seats, plus 2 wheelchair spaces) and output 42. It doesn't work. Which line is wrong?

A student's program — which line goes wrong?

Computer Science · Local and global variables

Same name, same box?

The main program has a global variable called count, holding 10. A subroutine called reset declares its own local variable, also called count, and sets it to 0. The main program calls reset(), then runs OUTPUT count.

What does the main program output? Pick the idea closest to what you think.
How sure are you?

Computer Science · Structured programming

One quiz game, built from modules
Main programgetAnswerisCorrectshowScorein: questionback: answerin: answer, correctback: True/Falsein: scoreback: nothing

Showing 2 layers: Structure chart, Interfaces

Layers

Explore

Turn Interfaces off to see the bare decomposition, then back on.

Each module's interface: the data that goes in through its parameters, and the value, if any, that comes back.

Tap a box, or its name under Explore, to read its interface: what goes in, and what comes back.

Computer Science · Subroutines

Your turn: why bother with subroutines?

A programmer is writing a large program. Explain two advantages of building it from subroutines. [4 marks]

0 words · your answer stays on this page and is not sent anywhere.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

What you need to know

  • A subroutine is a self-contained block of code with its own identifier that carries out a specific task. It runs when the main program (or another subroutine) calls it by that identifier; then control returns to where the call was made.
  • Procedures and functions are the two kinds of subroutine. A function returns a value to the code that called it; a procedure carries out its task without returning a value.
  • Parameters are the variables listed in a subroutine's definition. Arguments are the values supplied in the call, and they are passed to the parameters in order, so the same subroutine can work on different data.
  • A function sends its result back with a return statement. The returned value replaces the call, so it can be assigned to a variable, output or used in an expression.
  • A local variable is declared inside a subroutine, exists only while that subroutine runs and can only be accessed from within it. A global variable is declared in the main program and can be accessed from anywhere.
  • Structured programming builds a program from modules (subroutines), each with a clear interface: the data it takes in through its parameters and the value, if any, it returns.

The big picture

A subroutine is a named, self-contained block of code that does one job. Calling it makes control jump to it; when it finishes, control comes back to where the call was made. Arguments in the call are passed to the parameters in the definition. A function returns a value, which replaces the call in the calling code; a procedure returns nothing. Local variables exist only inside their subroutine while it runs, which keeps subroutines self-contained, and structured programs are built from subroutines with clear interfaces.

Key points

1Call, jump, run, return, carry on: control always comes back to the point of the call.
2The deciding test is RETURN. A value sent back makes it a function; no value sent back makes it a procedure. Outputting is not returning.
3Arguments are matched to parameters by position: first to first, second to second.
4Same identifier, different variables: a local variable can't change a variable of the same name anywhere else.
5Subroutines let you decompose a problem, reuse code without repeating it, test parts separately, make a change in one place and share the work.

Worked example

Problem

SUBROUTINE area(w, h) holds two lines: a ← w * h, then RETURN a. The main program runs x ← area(2, 5), then y ← area(x, 3) - 1, then OUTPUT y. What is output?

⚠ Watch out

Mixing up parameters and arguments. The parameters are the names in the subroutine's definition, like w and h in area(w, h). The arguments are the values in the brackets when you call it, like 2 and 5 in area(2, 5).

🧠

Memory hook

A function is a round trip that brings back a souvenir: it goes away, does the job and returns with a value. A procedure makes the same trip and comes home empty-handed.

✓

Check yourself

Without looking back: cube(n) returns n * n * n. In y ← cube(2) - 3, where does control go at the call, which parameter gets 2, and what does y hold? (y holds 5.)

Flashcards

(13)
What is a subroutine?
A self-contained block of code, with its own identifier, that carries out one specific task.
What happens to control when a subroutine is called?
It jumps to the subroutine, the subroutine's code runs, and then control returns to the point where the call was made.
What is the one difference between a function and a procedure?
A function returns a value to the code that called it. A procedure carries out its task without returning a value.
A subroutine OUTPUTs its answer but has no RETURN. Which kind is it?
A procedure. OUTPUT shows the value on screen; only RETURN sends it back to the calling code.
What is a parameter?
A variable listed in a subroutine's definition that receives data passed into the subroutine.
What is an argument?
A value supplied in the call, which is passed to one of the subroutine's parameters.
How are arguments matched to parameters?
In order: the first argument goes to the first parameter, the second to the second, and so on.
Where does a function's returned value go?
It replaces the call in the calling code, so it can be assigned to a variable, output or used in an expression.
What is a local variable?
A variable declared inside a subroutine. It exists only while that subroutine is running and can only be accessed from within it.
What is a global variable?
A variable declared in the main program. It can be accessed from anywhere in the program.
Why does using local variables make subroutines easier to reuse, test and debug?
Each subroutine stays self-contained: changes inside it can't accidentally alter data used elsewhere in the program.
What is structured programming?
Building a program from modules (subroutines), each with a clear interface.
What is a subroutine's interface?
The data it takes in through its parameters, and the value, if any, that it returns.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 30 September 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.