What is a function?

Going back to Chapter 1What is Programming?, you may remember that we defined programming as writing a set of instructions for a computer to execute. A function is a block of reusable code or instructions which generally performs a single specific task. A function abstracts one or more instructions and gives us a reference to that block of instructions. Chapter 4Favorite Things, showed us how to reference values using variables. In this chapter, you will learn that a function is basically a set of instructions or a chunk of code that is grouped together and referenced by a function name.

Let's imagine a real-world example for a moment. When you want to order a pizza, you call your local pizza joint. The people working at ...

Get Swift iOS Programming for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.