Data Wrangling with Swift Control Flow

Programming is all about making decisions. The purpose of most code involves taking information, inspecting it, making decisions, and producing an output. So far, we have seen a lot of ways to represent information, but in this chapter, we will explore how to make decisions based on that information using a number of Swift's control flow statements. We will find out how they differ and the situations where each is appropriate.

In this chapter, we will cover the following recipes:

  • Making decisions with if/else
  • Handling all the cases with switch
  • Looping with for loops
  • Looping with while loops
  • Handling errors with try, throw, do, and catch
  • Checking upfront with guard
  • Doing it later with defer
  • Bailing ...

Get Swift Cookbook - Second Edition 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.