Contents Previous Next Subchapters

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

Description
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.

Example

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
     clear
     function f(n) begin
          if n == 0 then begin
               print "cannot divide by", n
               return
          end
          print "1. / n =", 1. / n
     end
     f(0)
O-Matrix will respond
     cannot divide by 0
If you continue by entering
     f(1)
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
     clear
     function f() begin
          return 5 * 6
     end
     print f
O-Matrix will respond
     30

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