Subroutines: Functions and Procedures

GCSE Computer Science · Programming

What a subroutine is

A named block of code you can call whenever needed.

  • Procedure – does a task, returns nothing.
  • Function – does a task and returns a value.

Example

FUNCTION area(width, height)
    RETURN width * height
ENDFUNCTION

OUTPUT area(4, 5)      # 20
PROCEDURE greet(name)
    OUTPUT "Hello " + name
ENDPROCEDURE

greet("Sam")           # Hello Sam

Parameters vs arguments

  • Parameters – the variables in the definition (width, height).
  • Arguments – the actual values passed in (4, 5).

Why use them?

  • Reusability – write once, call many times.
  • Readability / maintainability – named, self-contained blocks.
  • Easier testing – test each part separately.

Local vs global variables

  • Local – exists only inside the subroutine (preferred — avoids accidental changes).
  • Global – accessible everywhere.

Exam tip

A function returns a value; a procedure does not. Stating this earns easy marks. Reuse and maintainability are the key benefits.

Don't understand a part?

Sign in and ask our AI tutor to explain any passage in plain English.

Try AI explanations →

More on Programming

Programming Fundamentals Selection and Iteration Arrays, Lists and Records String Manipulation

← All GCSE Computer Science notes