kotlin swithc

fun main() {
    val option = 2

    when (option) {
        1 -> println("Option is 1")
        2 -> println("Option is 2")
        3 -> println("Option is 3")
        else -> println("Option is neither 1, 2, nor 3")
    }
}
  1. Define a main function.
  2. Declare a variable option and assign it the value 2.
  3. Start a when expression to check the value of option.
  4. Check if option is equal to 1, print "Option is 1" if true.
  5. Check if option is equal to 2, print "Option is 2" if true.
  6. Check if option is equal to 3, print "Option is 3" if true.
  7. If none of the above conditions are met, execute the else block and print "Option is neither 1, 2, nor 3".