What you'll build
- A program that makes a repetitive song about a topic of your choosing.
What you'll learn
- How to avoid typing the same lines of code when you want to repeat the work they do.
- How to define and call functions.
- Why breaking down a program into small, understandable parts is a good idea.
Key vocabulary
Introduction
So far in this course, the code in your playgrounds has started at the top, run to the bottom and then stopped. If you wanted to do anything more than once, you’d have to type it again.
In this lesson, you’ll learn how to group your code into building blocks called functions. You'll also learn how to use those building blocks to repeat code easily, and how to assemble smaller blocks into larger, more powerful programs.
Keeping code inside a function makes it easier to tweak the way your program works. You’ll learn that it’s easier to understand and work with a large program made of smaller functions than one made up of many many lines of code.
Go Build
Open the Functions.playground file in your course resources and follow the instructions.

Reflection Questions
Think of a collection of everyday tasks that you perform, like getting ready in the morning.
How would you separate the activities into functions?
Can you reuse any of the functions for getting ready for bed at night?
The functions you've learned about so far are very specific. They do the same exact thing every time they’re called.
If you wanted to create functions to sing Happy Birthday to your friends, how many Happy Birthday functions would you have to write?
You’ve learned that functions group smaller tasks together.
How many small tasks do you think should fit inside one function before you rewrite it as two functions?
If you have only one or two small tasks in a function, is that too small?
How do you decide?
Summary
Functions are one of the fundamental building blocks of computer programs.
They allow your mind to focus on different levels of detail. When writing a function, you can concentrate on exactly what that single function does and how it does it. This is a fundamental computer science concept known as procedural abstraction. By breaking a problem into pieces, you can write functions to solve each piece independently. Once you know all the functions work, you can combine them to solve the bigger problem.
Later, when you write code that uses your function, you can put the how details to one side, and just remember what the function does. So you only need to concentrate on one level of detail at a time.
In the next lesson, you’ll learn more about how Swift distinguishes between different kinds of data.