Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Last active November 17, 2019 21:36
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 magdamiu/307da58d61f941905172d87b2e66f47b to your computer and use it in GitHub Desktop.
Save magdamiu/307da58d61f941905172d87b2e66f47b to your computer and use it in GitHub Desktop.
when
val firstValue = 6
val secondValue = 3
val operator = "/"
val resultOfOperation = when (operator) {
"+" -> firstValue + secondValue
"-" -> firstValue - secondValue
"*" -> firstValue * secondValue
"/" -> firstValue / secondValue
else -> "$operator operator is invalid."
}
println(resultOfOperation) // => 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment