Skip to content

Instantly share code, notes, and snippets.

@MostafaNasiri
Last active November 21, 2019 14:58
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/ef4cb1eff0da91e7cb6f01268f311b6e to your computer and use it in GitHub Desktop.
Save MostafaNasiri/ef4cb1eff0da91e7cb6f01268f311b6e to your computer and use it in GitHub Desktop.
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