Programs often need to do different things depending on the situation. Kotlin uses if and when to check conditions. What makes Kotlin's if and when special is that they can be expressions, so you can assign the result value directly into a variable.
kotlin
fun main() {
val score = 82
val result = if (score >= 50) "Passed" else "Failed"
println(result)
val grade = when (score) {
in 90..100 -> "A"
in 80..89 -> "B"
in 70..79 -> "C"
else -> "Needs practice"
}
println("Grade: $grade")
}You should see
Passed Grade: BSummary
if for simple decisions, when for multiple cases.