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’re explore more scenarios in which functions are useful and learn to define and use them in our code.
Click Next, when you’re ready to get started.