Last active
November 21, 2019 14:58
-
-
Save MostafaNasiri/ef4cb1eff0da91e7cb6f01268f311b6e 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 x = 2 | |
// Just a simple if expression | |
if (x % 2 == 0) { | |
println("Even") | |
} | |
// Example 2 | |
// Now we see how if expressions can return values | |
val message = if (x % 2 == 0) { | |
"Number is even" | |
} else { | |
"Number is odd" | |
} | |
println(message) | |
// Example 3 | |
// A shorter example | |
val num1 = 10 | |
val num2 = 5 | |
val max = if (num1 > num2) num1 else num2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment