Introduction to Subroutines (AQA GCSE Computer Science)

Revision Note

James Woodhouse

Expertise

Computer Science

Introduction to Subroutines

What is a subroutine? 

  • Subroutines are an out of line block of code that may be called by simply writing their name in a program     
  • Subroutines are given a unique name so they can be called anywhere in a program
  • There are many benefits to using subroutines, these include
    • Making bigger problems easier to break down (decompose) and code
    • Allows team members to be able to work on different parts of a problem
    • Makes the program easier to debug
    • Makes programs more efficient as code is not duplicated
  • More detailed information about subroutines can be found in the 'Structured Programming' section

Meaningful Identifiers

What are meaningful identifiers?

  • Meaningful identifiers are sensible names used for variables, constants or subroutines
  • A meaningful identifier must be used to help aid the maintainability of a program
  • An example would be a variable used for an input of a users' first name
Meaningful Identifier Poor Identifier

name ← USERINPUT

IF name == "Mike" THEN

cost ← 100 * 0.5

ELSE

OUTPUT name + " your total is: " + cost

a ← USERINPUT

IF a == "Mike" THEN

b ← 100 * 0.5

ELSE

OUTPUT a + " your total is: " + b

Examples of using subroutines

SUBROUTINE Information()

    first_name ← USERINPUT

    surname ← USERINPUT

ENDSUBROUTINE

SUBROUTINE Tax(pay_per_hour, hours_worked)

    total ← pay_per_hour * hours_worked

    net_pay ← total * 0.8

    RETURN net_pay

ENDSUBROUTINE

//Main program starts here

Information()

OUTPUT(Tax)

You've read 0 of your 0 free revision notes

Get unlimited access

to absolutely everything:

  • Downloadable PDFs
  • Unlimited Revision Notes
  • Topic Questions
  • Past Papers
  • Model Answers
  • Videos (Maths and Science)

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

James Woodhouse

Author: James Woodhouse

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.