Procedures and functions
About this lesson: Procedures and functions
In short
A subroutine is a named block of code. Calling it runs the block, then returns to where it was called.

What you'll explore
- Subroutines: Jump in, run, jump back
- A subroutine is a named block of code. Calling it runs the block, then returns to where it was called.
- Functions return a value: A routine that answers
- A function calculates and RETURNS a value; a procedure just does a job. Change the inputs.
- Why use them?: Write once, use many times
- Subroutines avoid repeated code, make programs easier to test and let teams split work.
- Check yourself: Procedure or function?
- A subroutine works out the VAT on a price and sends the result back.
Also in this lesson
- Step by step
- Watch out for these
- More than the lesson
- Stretch your brain
- Try it yourself
Words to know
- Subroutine
- A named block of code that can be called.
- Procedure
- A subroutine that does not return a value.
- Function
- A subroutine that returns a value.
- Call
- Running a subroutine.
- Return value
- The value a function sends back.
Sources
- Python documentation: defining functions
- Raspberry Pi Foundation, Isaac Computer Science: subroutines
- Computer History Museum: EDSAC and early subroutines
- BBC Bitesize, GCSE Computer Science: subroutines