April 2026
Intermediate
683 pages
25h 29m
English
In this section, you’ll learn about control transfer statements, which are used to manipulate the natural flow of a code block, such as in the following ways:
Exiting the block earlier than anticipated
Skipping an iteration
Enforcing an iteration
Raising an error
Performing initial condition checks for execution enablement
Now, let’s go over the keywords that lead to such control transfer statements and implement corresponding code examples.
In Swift, the break keyword is used to exit a loop early, before it naturally finishes. To see this command in a familiar context, Listing 4.42 demonstrates the former login example—with a small enhancement.
let correctPassword = "abcde"var
Read now
Unlock full access