Skip to content
Gallery
Kotlin
Share
Explore
Kotlin Documenation

icon picker
Conditional expressions

If-else

var max = a
if (a < b) max = b

// With else
if (a > b) {
max = a
} else {
max = b
}

// As expression
max = if (a > b) a else b

// You can also use `else if` in expressions:
val maxLimit = 1
val maxOrLimit = if (maxLimit > a) maxLimit else if (a > b) a else b
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.