3

Conditionals and Optionals

In the previous chapter, you looked at data types, constants, variables, and operations. At this point, you are able to write simple programs that process letters and numbers. However, programs don’t always proceed in sequence. Oftentimes, you will need to execute different instructions based on a condition. Swift allows you to do this by using conditionals, and you will learn how to use them in this chapter.

Another thing you may have noticed is that, in the last chapter, each variable or constant was immediately assigned a value. What if you require a variable where the value may not be present initially? You will need a way to create a variable that may or may not have a value. Swift allows you to do this by

Get iOS 16 Programming for Beginners - Seventh 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.