Returning from a Function

Functions can give you information after they finish executing the code inside of their implementation. This information is called the return of the function. It is often the case that you write a function to do some work and return you some data. Make your divisionDescription(forNumerator:andDenominator:withPunctuation:) function return an instance of the String type.

Listing 12.8  Returning a string

...
func divisionDescription(forNumerator num: Double,
                         andDenominator den: Double,
                         withPunctuation punctuation: String = ".") {
    print("\(num) divided by \(den) equals
           \(num / den)\(punctuation)")
}
divisionDescription(forNumerator: 9.0, andDenominator: 3.0)
divisionDescription(forNumerator: 9.0, andDenominator: ...

Get Swift Programming: The Big Nerd Ranch Guide 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.