Skip to content

Instantly share code, notes, and snippets.

@arsalankhan994
Created February 12, 2022 13:20
Show Gist options
  • Select an option

  • Save arsalankhan994/4a1b3eb53ca045103a88668ef2126d67 to your computer and use it in GitHub Desktop.

Select an option

Save arsalankhan994/4a1b3eb53ca045103a88668ef2126d67 to your computer and use it in GitHub Desktop.

Revisions

  1. arsalankhan994 created this gist Feb 12, 2022.
    14 changes: 14 additions & 0 deletions WhenElseKotlin.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    fun main() {

    // Multi Condition in Kotlin using when/else

    val list = listOf("Erselan Khan", 27, "arsalankhan994@gmail.com")

    when(list[(list.indices).random()]) {
    "Erselan Khan" -> println("name is ${list[0]}")
    27 -> println("age is ${list[1]}")
    "arsalankhan994@gmail.com" -> println("email is ${list[2]}")
    else -> println("Else condition")
    }

    }