Contents Previous Next Subchapters

Returning from a Function
Syntax return
return value
See Also defining functions , multiple return values

The return statement terminates execution of the current function and returns execution to the routine that called the function. If value is present, it is the value corresponding to the function in the calling routine.


Multiple Return Points
There is an automatic return at the end of every function. You can define other return points using the return statement. If you enter
     function f(n) begin
          if n == 0 then begin
               print "cannot divide by", n
          print "1. / n =", 1. / n
O-Matrix will respond
     cannot divide by 0
If you continue by entering
O-Matrix will respond
     1. / n = 1

Returning A Value
If value is present, it will be the value of the function name in the calling routine. If you enter
     function f() begin
          return 5 * 6
     print f
O-Matrix will respond

A return value cannot be specified in the return statement if the multiple return value syntax is used to define the function.