Skip to main content
EnglandComputer ScienceSyllabus dot point

How do we split a program into reusable named blocks?

Use subroutines (procedures and functions), pass parameters and return values, and understand the scope of local and global variables.

A focused answer to AQA GCSE Computer Science 3.2.8, covering subroutines (procedures and functions), passing parameters, returning values, and the scope of local and global variables.

Generated by Claude Opus 4.88 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. Subroutines
  3. Procedures and functions
  4. Parameters
  5. Variable scope
  6. Why subroutines are worth using
  7. Try this

What this dot point is asking

AQA wants you to use subroutines (procedures and functions), pass parameters into them and return values from functions, and explain the scope of local and global variables.

Subroutines

Procedures and functions

FUNCTION area(radius)
    RETURN 3.14159 * radius * radius
ENDFUNCTION

Here area(5) returns a value you can store or use, whereas a procedure such as printMenu() simply does something (displays a menu) and returns nothing.

Parameters

Parameters are what make a subroutine general: area(radius) works for any radius because the value is passed in, rather than the radius being fixed inside the subroutine.

Variable scope

Local variables are usually preferred because they cannot be changed accidentally by other parts of the program, which avoids side effects and makes subroutines self-contained, easier to test and safe to reuse. A local variable is also created fresh each time its subroutine runs and destroyed when it ends, so two subroutines can use the same name without clashing.

Why subroutines are worth using

Subroutines bring the same benefits as structured programming because they are its building block. Writing a task once as a subroutine and calling it many times avoids repeating code, so there is less to write and only one place to fix if it is wrong. Each subroutine can be tested on its own with known inputs and expected outputs before the rest of the program is finished. A clear interface (parameters in, return value out) plus local variables keeps a subroutine self-contained, so it can be reused in other programs and changed internally without affecting the code that calls it, as long as the interface stays the same.

Try this

Q1. State one difference between a function and a procedure. [2 marks]

  • Cue. A function returns a value; a procedure carries out a task without returning one.

Q2. Give one reason local variables are preferred to global variables. [1 mark]

  • Cue. They cannot be changed accidentally by other subroutines, avoiding side effects.

Exam-style practice questions

Practice questions written in the style of AQA exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

AQA 20205 marksWrite an AQA-style function called area that takes the radius of a circle as a parameter and returns its area, using 3.14159 for pi. State what value area(2) returns and explain why a function rather than a procedure is appropriate here.
Show worked answer →

A correct function:

FUNCTION area(radius)
RETURN 3.14159 * radius * radius
ENDFUNCTION

area(2) returns 3.14159×2×2=12.566363.14159 \times 2 \times 2 = 12.56636.

A function is appropriate because the subroutine produces a value (the area) that is needed back at the point of call, and a function returns a value whereas a procedure does not.

Markers reward a function with a parameter and a RETURN of the correct formula, the value about 12.57, and the reason (it returns a value).

AQA 20224 marksExplain the difference between a local and a global variable, and explain one reason why using local variables in subroutines is considered good practice.
Show worked answer →

A local variable is declared inside a subroutine and only exists, and can only be used, within that subroutine; it is created when the subroutine runs and destroyed when it ends. A global variable is declared in the main program and can be used anywhere in the program.

Using local variables is good practice because they cannot be changed accidentally by other parts of the program, which avoids unexpected side effects and keeps each subroutine self-contained and easier to test and reuse.

Markers reward the scope distinction (inside one subroutine versus whole program) and a reason (avoids accidental change and side effects).

Related dot points

Sources & how we know this