Skip to content

Instantly share code, notes, and snippets.

@MostafaNasiri
Last active November 22, 2019 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MostafaNasiri/97b293a02945ee0cb637deba508fe5ae to your computer and use it in GitHub Desktop.
Save MostafaNasiri/97b293a02945ee0cb637deba508fe5ae to your computer and use it in GitHub Desktop.
fun main() {
// Example 1
val firstNum = 1
val message = when (firstNum) {
1 -> "One"
2 -> "Two"
3 -> "Three"
else -> "Unknown Number" // "else" is mandatory here
}
// Example 2
val secondNum = 13
when {
firstNum % 2 == 0 -> print("Divisible by 2")
firstNum % 5 == 0 -> print("Divisible by 5")
else -> print("Not divisible by 2 or 5")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment