In an earlier chapter, you saw one sort of conditional statement:
Along the way, we mentioned that
if/else can be somewhat inadequate in scenarios that have more than a few conditions.
This chapter looks at the
switch is ideal for handling multiple conditions.
As you will see, Swift’s
switch statement is an incredibly flexible and powerful feature of the language.
if/else statements execute code based on whether the condition under consideration evaluates to true.
switch statements consider a particular value and attempt to match it against a number of cases.
If there is a match, the
switch executes the code associated with that case. Here ...