Introduction to Conditionals

On a daily basis, weโ€™re faced with making decisions based on certain conditions; if the weather is beautiful, weโ€™ll go for a walk, or if itโ€™s rainy, weโ€™ll stay in and code!

In Swift, the ability to determine an outcome based on a given condition also exists. Itโ€™s known as a conditional.

Conditionals are powerful programming tools that introduce flexibility and complex behavior to a program by allowing it to react to change. Their power comes from being the root of all decision making within an application.

Your computer, for example, contains authentication processes whose logic is handled by conditionals. If you are logged out, access to certain pages on your device may be restricted, or if your are logged in, access will be granted.

In this lesson, weโ€™ll set up our own rules and conditions for programs to follow using Swiftโ€™s conditional statements and operators.


Take a look at our Swifty Donut ๐Ÿฉ factory on the right. Notice how conditionals are responsible for all the processes within this factory. If a donut should be chocolate flavored, it lands on one conveyor belt, if itโ€™s strawberry, it lands on another and so on!

Whatโ€™s another conditional you can think of used in this factory?

Folder Icon

Take this course for free

Already have an account?