Branching with if and else in Scala is straightforward.
To run the program:
Note that in Scala, you don’t need parentheses around conditions, but they are allowed. Curly braces are required for multi-line blocks but can be omitted for single-line expressions.
Unlike some other languages, Scala does have a ternary-like operator in the form of an if-else expression:
This can be used for concise conditional assignments.