December 2015
Intermediate to advanced
400 pages
13h 3m
English
Let’s revisit control transfer statements in the context of loops.
Recall from Chapter 5 (where you used fallthrough and break) that control transfer statements change the typical order of execution.
In the context of a loop, you can control whether execution iterates to the top of the loop or leaves the loop altogether.
Let’s elaborate on the space shooter game to see how this works.
You are going to use the continue control transfer statement to stop the loop where it is and begin again from the top.
Listing 6.7 Using continue
var shields = 5
var blastersOverheating = false
var blasterFireCount = 0
while shields > 0 {
if blastersOverheating {
print("Blasters are overheated! Cooldown initiated.") ...Read now
Unlock full access