Functions and Procedures
A function is a reusable block of code that performs a task and can take inputs and return a result.
▶ Interact
Play with the controls to see the idea in action.
📘 Learn
A function is a reusable block of code that performs a task and can take inputs and return a result.
- Parameters pass data in
- Return gives a value back
- Functions make code shorter and clearer
🧠 Quick quiz
Three questions. Score 2 or more to complete the topic.
What is Functions and Procedures?
Within Computer Science, which covers algorithms, programming, data, networks, hardware and safe, responsible use of technology, this topic explains Functions and Procedures. Computing topics explain how software, hardware and data work, with diagrams and models that show each step in order.
Check that you can explain Functions and Procedures in your own words and give one example from everyday life. If you can do that, you have understood the core idea.
Understanding Functions and Procedures helps you design, test and explain programs, websites and systems, from small projects to exam questions.
Functions and Procedures in detail
A subroutine is a named block of code that carries out a specific task and can be called whenever needed. A procedure carries out actions and does not return a value, whereas a function returns a value to the part of the program that called it.
Subroutines can take parameters, which are values passed in, making them flexible. They reduce repetition, make programs easier to read, test and maintain, and allow teamwork on different parts. Built-in functions such as len() and print() are examples. Good design gives each subroutine one clear job and a descriptive name.
How the interactive helps you understand Functions and Procedures
Click a step, or use the Previous and Next buttons, to move through the sequence one stage at a time. Auto-play moves on for you.
Before you change anything, predict the result. Then change one value at a time and check whether your prediction was right. This is a quick way to build a correct mental model of Functions and Procedures.
Real-life uses and examples
- Apply Functions and Procedures when you design a small program, website or spreadsheet.
- Explain Functions and Procedures to someone new to computing by comparing it to a familiar process.
- Trace through a process that uses Functions and Procedures to check what it does step by step.
Common mistakes to avoid
- Testing only the normal case and forgetting the edge cases.
- Using the term without being able to say what the computer actually does.
- Learning the definition without testing it. Use the quiz and the interactive to check that you can apply the idea.
Frequently asked questions about Functions and Procedures
What is Functions and Procedures?
A function is a reusable block of code that performs a task and can take inputs and return a result.
What are the most important points about Functions and Procedures?
The main points are: Parameters pass data in; Return gives a value back; Functions make code shorter and clearer.
Why is Functions and Procedures useful?
Understanding Functions and Procedures helps you design, test and explain programs, websites and systems, from small projects to exam questions.
How can I practise Functions and Procedures?
Open the interactive at the top of this page and change the controls one at a time. Predict the result before each change, then take the three-question quiz. A score of two or more marks the topic as complete on this device.
Which topics are related to Functions and Procedures?
Related topics in Computer Science include Validation and Verification, Searching Algorithms, Recursion.