📁 Paper 1 · 3.2 Programming
3.2.10a Subroutines — Procedures & Functions
AQA 8525 · GCSE Computer Science · ~10 min read
Notes
──
Video
──
Worksheet
──
Quiz

What is a Subroutine?

A subroutine is a named block of code that performs a specific task. You define it once and call it as many times as needed from anywhere in your program. This is called code reuse.

There are two types of subroutine in AQA:

TypeReturns a value?Called usingAQA keyword
ProcedureNoName onlySUBROUTINE / ENDSUBROUTINE
FunctionYes (via RETURN)Name in expressionSUBROUTINE / RETURN / ENDSUBROUTINE

Why Use Subroutines?

  • Code reuse — write once, call many times
  • Decomposition — break a large problem into smaller manageable parts
  • Easier to test — each subroutine can be tested independently
  • Easier to maintain — fix a bug once in the subroutine, not in 10 places
  • Readability — meaningful subroutine names make code self-documenting

Procedures (no return value)

A procedure performs an action but does not send back a result. It is called by name.

SUBROUTINE greetUser() OUTPUT "Welcome to CSZone!" ENDSUBROUTINE // Calling the procedure: greetUser() // Outputs: Welcome to CSZone! greetUser() // Can call it multiple times

Procedure with parameters

SUBROUTINE printBorder(length) FOR i ← 1 TO length OUTPUT "*" ENDFOR ENDSUBROUTINE printBorder(10) // Prints 10 stars printBorder(5) // Prints 5 stars

Functions (return a value)

A function computes a value and returns it to the calling code using RETURN. The returned value can be stored in a variable or used directly.

SUBROUTINE square(n) RETURN n * n ENDSUBROUTINE result ← square(5) // result = 25 OUTPUT square(3) // Outputs: 9 OUTPUT square(7) // Outputs: 49

Function with multiple parameters

SUBROUTINE calculateAverage(a, b, c) total ← a + b + c RETURN total / 3 ENDSUBROUTINE avg ← calculateAverage(80, 90, 70) OUTPUT "Average: " + str(avg) // Average: 80.0

Calling Pattern

When a subroutine is called, execution jumps to the subroutine, runs its code, then returns to the line after the call. Functions additionally send back a return value.

// Main program flow: OUTPUT "Start" greetUser() // ← jumps to subroutine, then returns here OUTPUT "End"
Exam tip: In AQA, BOTH procedures and functions use SUBROUTINE...ENDSUBROUTINE. The difference is that functions have a RETURN statement. When asked to write a function, always include RETURN with the result.
⚠️ Common Mistakes
  • Forgetting RETURN in a function — without it, nothing is sent back
  • Calling a function without using its return value — result is lost
  • Not calling the subroutine — defining it does nothing on its own
  • Confusing procedure (does something) with function (calculates something)
Video coming soon

Key points

  • Subroutines = procedures (no return) + functions (RETURN value)
  • AQA uses SUBROUTINE...ENDSUBROUTINE for both
  • Benefits: code reuse, decomposition, easier testing
  • RETURN sends a value back from a function
Click slide or press arrow keys to navigate
✍️

Worksheet — 3.2.10a Subroutines

8 questions · 20 marks

Q1State TWO benefits of using subroutines in a program.[2]
✅ Mark scheme
Mark scheme
Any two from: code reuse — write once, call many times [1]; easier to test — each subroutine tested independently [1]; decomposition — breaks problem into smaller parts [1]; easier to maintain/debug [1]; improved readability [1] — max 2.
Q2State the difference between a procedure and a function.[2]
✅ Mark scheme
Mark scheme
A procedure performs an action but does not return a value [1]; a function computes and returns a value to the calling code using RETURN [1].
Q3Write a procedure called 'printDivider' that outputs a row of 20 dashes.[3]
✅ Mark scheme
Mark scheme
SUBROUTINE printDivider() [1]; FOR i ← 1 TO 20 OUTPUT "-" ENDFOR (or OUTPUT "----...----") [1]; ENDSUBROUTINE [1].
Q4Write a function called 'cube' that takes a number n and returns n³.[3]
✅ Mark scheme
Mark scheme
SUBROUTINE cube(n) [1]; RETURN n * n * n (or n^3) [1]; ENDSUBROUTINE [1].
Q5What will the following output? SUBROUTINE double(x) RETURN x * 2 ENDSUBROUTINE OUTPUT double(7)[1]
✅ Mark scheme
Mark scheme
14 [1] — double(7) returns 7*2 = 14.
Q6Write a function 'isEven' that takes an integer and returns True if it is even, False otherwise.[3]
✅ Mark scheme
Mark scheme
SUBROUTINE isEven(n) [1]; IF n MOD 2 == 0 THEN RETURN True ELSE RETURN False ENDIF [1]; ENDSUBROUTINE [1].
Q7Explain why using subroutines makes a program easier to maintain when a bug is found.[2]
✅ Mark scheme
Mark scheme
The bug only needs to be fixed once in the subroutine definition [1]; whereas without subroutines, the same code repeated in many places would all need updating individually [1].
Q8Write a complete program that defines a function 'celsiusToFahrenheit' (formula: F = C * 9/5 + 32), then calls it 3 times with values 0, 100, and 37.[4]
✅ Mark scheme
Mark scheme
SUBROUTINE celsiusToFahrenheit(c) RETURN c * 9/5 + 32 ENDSUBROUTINE [2]; OUTPUT celsiusToFahrenheit(0) [1]; OUTPUT celsiusToFahrenheit(100); OUTPUT celsiusToFahrenheit(37) [1].
Check your answers above.
Topic Quiz
Q 1 of 10
You scored
out of 10
Card 1 of 6
Click to flip
🎉
All done!
TermDefinition
🎯

Mini Test — 3.2.10a Subroutines

Timed exam conditions.

  • 8 questions · 10 minutes
  • 5 MCQ + 3 short answer
← 3.2.8 Random Numbers
20 of 57 · AQA 8525
3.2.10b Parameters & Returns →