if / else
Branching based on a condition (expression).
Syntax
if (condition) ... else ...
Description
In Scala, if is an expression: produces a value with val x = if (a) 1 else 2. Curly braces are used for blocks.
Example
Loading editor…
This language is for reference/learning only — copy the code and try it in your own environment.
Expected output
Adult
When to use?
Decision making, conditional value selection.