Previous Page Next Page Contents

return -- exit a procedure

Introduction

return(x) terminates the execution of a procedure and returns x.

Call(s)

return(x)

Parameters

x - any MuPAD object

Returns

x.

Related Functions

DOM_PROC, proc, ->

Details

Example 1

This example shows the implementation of a maximum function (which, in contrast to the system function max, accepts only two arguments). If x is larger than y, the value of x is returned and the execution of the procedure mymax stops. Otherwise, return(x) is not called. Consequently, y is the last evaluated object defining the return value:

>> mymax := proc(x : Type::Real, y : Type::Real)
   begin
      if x > y then
        return(x)
      end_if;
      y
   end_proc:
>> mymax(3, 2), mymax(4, 5)
                                   3, 5
>> delete mymax:

Example 2

return() returns the void object:

>> f := x -> return(): type(f(anything))
                                 DOM_NULL
>> delete f:

Example 3

If return is called on the interactive level, the evaluated arguments are returned:

>> x := 1: return(x, y)
                                   1, y
>> delete x:

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000