v If Else - Scala

If Else

If you want a deeper guide to Scala, when I was learning I used Programming Scala and Scala for Data Science.

Create A Value

// Create a value called x that is a short integer of 3
val x: Short = 3

Create A Conditional Expression

// Create a value that is 1 if x is greater than 0, otherwise -1
val binary = if (x > 0) 1 else -1

// View that value
binary
1