Return

Flow control
Aptilis 1

Return

return expr

return is used within subs, usually at the end, to return a value.
You can use a return statement within a loop if you have reached a point where you want to exit from the sub.
A return is not necessary as you may have subs that do things but do not need to return a value. The value returned by a sub with no return statement is not predictible.
You might also use return on its own, without a value, just to exit from a sub.
A value returned at the end of the main procedure is converted to an integer and is returned to the calling process (A fact that Unix users will appreciate).

Example

sub main

// This is a programm to extract the square root of a number
// The number has to be typed in by the user.

n = input(20)


// There is no square root to a negative (real) number.
if n < 0
return
end if

r = ComputeSquareRoot(n)
print(r, "\n")


end main


sub ComputeSquareRoot(v)

// Actually, square root is a built-in sub. :-)
sq = Sqr(v)

return sq

end ComputeSquareRoot
See sub.