0
what is fallthrough in swift ? why it is used?
2 Answers
0
Seems to allow for calling the next case, even if the object doesn't match by search parameter. Cant think of a use case for it...
0
Fallthrough is when a switch executes a case then "falls through" to execute the next case in the same switch. In some languages this happens by default and can be prevented with "break." However, in Swift the default is *not* to fall through; instead just one case executes unless you explicitly direct it to fallthrough.
An example is if you have a switch with five cases and you want to skip the first two and execute all of the last three. You could execute case three and then fall through to execute the subsequent two cases as well.