Understanding functions
Let's say you would like to do the following:
- Calculate the 10% service charge for a meal at a restaurant.
- Calculate the monthly payment for a car that you wish to purchase.
You can use a function to do this. A function contains a number of instructions that perform a specific task. You can define one or more values that the function takes as input, known as parameters. You can also define a value that the function will output when done, known as its return type. Both parameters and return types are optional.
Every function has a descriptive name. You "call" a function's name to execute it, and provide input values (known as arguments) that match the type of the function's parameters.
Here's what a function looks like:
func functionName(parameter1: parameterType, ...) -> returnType { code }
Important information
To learn more about functions, visit...