← Computer Science

Procedures, Functions and Parameters

Subroutines let you name a block of code once and reuse it. In this lesson we separate a procedure from a function, see why we bother writing subroutines at all, and learn to pass values in with parameters and get a value back with a return.

Slide 1 / 4

Two kinds of subroutine

A function returns a value; a procedure does notPROCEDUREGreetinnothing returnedFUNCTIONSquareinRETURN value out
  • A subroutine is a named block of code you can call from elsewhere in a program, so you write the instructions once and reuse them many times.
  • A procedure carries out a task but does not send a value back to the line that called it; in Cambridge pseudocode it is written with PROCEDURE ... ENDPROCEDURE.
  • A function carries out a task and RETURNs a single value to the point where it was called, so the returned value can be used in an expression or stored in a variable.
  • The key difference to remember is that a function returns a value and a procedure does not.

Check you've got it

0/4

1. What is the essential difference between a function and a procedure?

2. Which of these is NOT a reason for using subroutines?

3. In the call Total <- Add(4, 6), what is the role of the values 4 and 6?

4. A variable is declared inside a function and used only within it. What is this variable called?

Practise real exam questions on this

Type your answer, see your mark against the mark scheme in seconds. Free, 5 a day.

Start practising →

Teaching this topic?

Mark your whole class's answers and see who's stuck, for £19 a month.

See the class plan →

Free revision content. Multiple-choice answers are marked instantly. Written answers are marked by AI on /free-mark.