Loops and String Interpolation

Swift has all the control flow statements that you may be familiar with from other languages: if-else, while, for, for-in, repeat-while, and switch. Even if they are familiar, however, there may be some differences from what you are accustomed to. The key difference between these statements in Swift and in C-like languages is that while enclosing parentheses are not necessary on these statements’ expressions, Swift does require braces on clauses. Additionally, the expressions for if and while-like statements must evaluate to a Bool.

Swift does not have the traditional C-style for loop that you might be accustomed to. Instead, you can accomplish the same thing a little more cleanly using Swift’s ...

Get iOS Programming: The Big Nerd Ranch Guide, 6th 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.