|
|
|
|
|
by mrighele
1339 days ago
|
|
In a functional language technically you don’t have multiple returns, because the function is a single expression so in a way you’re right. On the other hand the actual result of the expression is determined on a leaf of the expression so you could consider it a return point To make an example the following expression can be considered to have two returns: max x y =
if x > y
then x
else y
The Java equivalent is int max(int x,int y) {
if (x>y)
return x;
else
return y;
}
Some people abhor the idea of having multiple returns in a method, and say that you should write it like int max(int x, int y) {
int result;
if (x>y)
result = x;
else
result = y;
return result;
}
(Disclaimer: Contrived and buggy example as I am on mobile) |
|