At times, you want to execute different code blocks based on a condition, such as in the following scenarios:
- Choosing between different room types at a hotel. The room price for bigger rooms would be higher.
- Switching between different payment methods at an online store. Procedures for different payment methods would be different.
- Deciding what to order at a fast-food restaurant. Preparation procedures for each food item would be different.
To do this, you would use conditionals. In Swift, this is implemented using if and switch statements. Let's take a look at them now.
For more information on conditionals, visit https://docs.swift.org/swift-book/LanguageGuide/ControlFlow.html.