if/then/else Expressions (Scala 3 Video)
if/then/else
is similar to other languages:
// [1]
if a < b then
println("less")
else
println("more")
// [2]
if a < b then
//
else if a > b
//
else if a == b
//
else
//
Can optionally add end if
at the end:
if a < b then
println("less")
else
println("more")
end if
&&
(and) and ||
(or):
if a < b && a < c then
// your code
else
// your code
if/then/else
is an expression, so you can use it as a ternary operator:
val rez = if a < b then a else b
Update: All of my new videos are now on
LearnScala.dev