if / else
Branching based on a condition (can also be an expression).
Syntax
if (condition) { ... } else { ... }Description
The condition is written in parentheses. In Kotlin, if can also produce a value: val x = if (a) 1 else 2.
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, input control.