December 2014
Beginner
300 pages
8h 9m
English
It’s important to have some control over your switch statements and loops. You can use break, continue, and labels to control them.
Using break stops any kind of loop (for, for in, or while) from carrying on. Say that you’ve found what you were looking for, and you no longer need to waste time or resources looping through whatever items remain. Here’s what you can do:
var mystery = 5for i in 1...8 { if i == mystery { break } println(i) // Will be 1, 2, 3, 4}
The loop will never print 5 and will never loop through 6, 7, or 8.
Much like break, continue will skip to the next loop and not execute any code below the continue. If you start with the previous ...
Read now
Unlock full access