1.1.50.1. fejezet, Folyamat vezérlés - Elágazás

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
 
# last expression is the value of a block
val max = if (a > b) {
    print("Choose a")
    a
} else {
    print("Choose b")
    b
}
 
if (max in 1..5) println("In range") else println("Not in range")