You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code prints (), as a evaluates to the Unit value:
vala=iffalsethen1elseiftruethen2
println(a)
Update: this code may be a bit too minimized to demonstrate the scope of the actual problem. See the examples in this comment for more clarity.
Output
()
Expectation
Although this code is unusual and unlikely to be written by an experienced programmer (it is a simplified and minimized version of something written by my 8-year-old son who has just started learning to program with Scala), I suspect most people would intuitively expect a to evaluate to 2 rather than to ().
Adding an unconditional else clause to the if statement restores expected behaviour:
vala=iffalsethen1elseiftruethen2else3
println(a) // prints 2