Last active
November 22, 2019 09:45
-
-
Save MostafaNasiri/97b293a02945ee0cb637deba508fe5ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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