Seneca

Subroutines

Computer Science: KS3, topic 2.1.10

Subroutines

A subroutine is a named block of code within your program.

Advantages of subroutines

Advantages of subroutines

  • Easier to read:
  • There are fewer long blocks of code to understand.
  • More efficient:
  • Blocks of code can be written once and reused many times.
  • More reliable:
  • Each subroutine can be individually tested to make sure it works.
Parameters and arguments

Parameters and arguments

  • Parameters are special variables used to pass values into a subroutine.
  • Arguments are the actual values that are passed in.
Types of subroutine

Types of subroutine

  • A function is a subroutine which returns a value.
  • A procedure is a subroutine which does not return a value.

Test yourself on Subroutines

  • A subroutine is defined to take two values, called x and y, and it returns their sum. Is x a parameter or an argument?

  • What is an argument of a subroutine?

  • Pick the statement that is true.

  • Why does splitting a program into subroutines make it easier to read?

Practise this topic for free