Chapter 3: Conditionals and Optionals
In the last 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 using optionals, and you will also learn about them in this chapter.
By the end of this chapter, you should be able to write programs that do different things based on different conditions, and to handle variables that may or may...