Control Transfer Statements in Swift
break, continue, fallthrough, throw and return
Published in
3 min readApr 16, 2020
Swift has five control transfer statments. What are they, and how can they be used?
continue
break
fallthrough
return
throw
Difficulty: Beginner | Easy | Normal | Challenging
Prerequisites:
- Some way of coding with Swift, either through Playgrounds or through a simple application.
Along with:
- Some knowledge of loops, functions, switches and Arrays. Some further knowledge of errors (although this is tricky) would help you to understand throws.
Terminology
break: Breaks the current execution whenever the keyword is encountered
continue: Stops the execution of a loop at the current point, and returns control to the next iteration of the loop
Control Transfer Statements: Keywords that allow you to transfer control from one piece of code to another
fallthrough: Make a Switch run the next case after a match
return: Make a function return