Learn

Each program we’ve written so far, whether it tested values against conditional statements or looped for iteration, executed explicitly in the order we’ve laid out and any code that needed to be reused would have to be typed out again.

As our programs get more complex, we’ll seek more efficient ways of organizing our code and aim to avoid repetition. This is where functions truly shine.

Swift functions are chunks of reusable code that achieve a certain outcome. Take a look at Sud City’s carWash() function on the right. The function contains numerous tasks that work together to achieve a clean car. Now each time we’d need our car washed, we wouldn’t build a new car wash, we’d simply reuse the one that already exists.

In this lesson, we’ll explore more scenarios in which functions are useful and learn to define and use them in our code.

Instructions

Click Next, when you’re ready to get started.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?