Similarly to the if statement, when can also be used as an expression. To do this, create a variable and assign when as an expression as follows:
fun main(args: Array<String>) {
val grade = "A"
val remarks = when (grade) {
"A","a" -> "Excellent"
"B","b" -> "Very Good"
"C","c" -> "Nice work"
"D","d" -> "OK"
"E","e" -> "Hmmm"
"F","f" -> "Better luck next time"
else -> "Invalid input"
}
println(remarks)
}