8. Miscellany

Swift is a vibrant and evolving language with many features that don’t fit tidily under a single umbrella. This chapter introduces an assortment of topics that did not otherwise have proper homes elsewhere in this book but that still deserve your attention.

Statement Labels

In various languages, commands like break, continue, return, and goto address program flow, enabling you to conditionally redirect execution from loops, switches, and other scopes. Swift offers control flow features including continue and break for loops, break and fallthrough for switches, and so forth. Here’s an example that uses continue to skip a print statement whenever an index is odd:

for index in 0...5 {     if index % ...

Get The Swift™ Developer’s Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.