Branching with if and else in Swift is straightforward.
To run this Swift code, you can save it in a file (e.g., if_else.swift) and execute it using the Swift command-line tool:
Note that you don’t need parentheses around conditions in Swift, but the braces are required.
Swift also provides a ternary conditional operator ?:, which can be used for simple conditional expressions. However, for more complex conditions, it’s generally better to use a full if statement for clarity.