You learned about Swift’s conditional statements in Chapter 3, but there is one more to introduce:
guard statements execute code depending on a Boolean value resulting from some expression.
guard statements are different from what you have seen before.
guard statement is used to exit early from a function if some condition is not met.
As their name suggests, you can think of
guard statements as a way to protect your code from running under improper conditions.
Following the example above, consider an example in which you want to write a function that greets a person by their middle name if they have one. If they do not have a middle name, you would ...