develop with

Condition and switches

Kotlin conditions and switches


Ternary operator approach

Kotlin doesn’t have a specific ternary operator like you would see in other languages, but it does allow you to use conditions within a variable assignment. This can mimic the behavior of a ternary.

Kotlin ternary example:

val myValue = if(cond) 
  "my value"
  else "my other value"

Next: Static Blocks

comments powered by Disqus

Want to see a topic covered? create a suggestion

Get more developer references and books in the developwith store.