Kotlin uses the same if/else statement structure as most of the C-like languages and uses the same comparison operators.
val name = "Link"
if(name == "Link"){
println("It's dangerous to go alone, take this!")
} else if (name == "Mario") {
println("The Princess is in Another Castle.")
} else {
println("Do a barrel roll!")
}💡 Kotlin has the
===and!==comparison operators, similar to Javascript. These operators evaluate based on reference
Conditional expression
A very nice feature of Kotlin language is to assign an if/else to a value.
val level = if(name == "Link") {
5
} else {
0
}
// You can omit the {}s when a branch contains one expression
val level = if(name == "Link") 5 else 0