-
Notifications
You must be signed in to change notification settings - Fork 0
Labelled statements
Radu Ghitescu edited this page Oct 12, 2020
·
1 revision
Use labelled statements to make it clear which statements should be affected by break and continue:
gameLoop: while square != finalSquare {
diceRoll += 1
if diceRoll == 7 { diceRoll = 1 }
switch square + diceRoll {
case finalSquare:
// diceRoll will move us to the final square, so the game is over
break gameLoop
case let newSquare where newSquare > finalSquare:
// diceRoll will move us beyond the final square, so roll again
continue gameLoop
default:
// this is a valid move, so find out its effect
square += diceRoll
square += board[square]
}
}
print("Game over!")