The return
keyword exists in Scala, but you rarely need it.
The return value of a method in Scala is simply the value of the last expression in the method; you can leave out the return
keyword.
Note that in Scala, if
is an expression and not a statement - it evaluates to a value. For example, you can assign the result of an if
expression to a variable:
val result = if (x == 3) 5 else 7
You could rewrite your code like this:
if (value == 0) 1
else if (value == 1) 0
else if (some.other.value.is.something) 0
else recursiveCall(some, stuff)
(assuming that recursiveCall(some, stuff)
also returns a value).