Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

return

Exit a procedure

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Syntax

return(x)

Description

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

Usually, MuPAD® ends a procedure when all statements of the procedure body were processed. In this case, the return value of the procedure is the result of the last statement that was executed.

Alternatively, the call return(x) inside a procedure leads to immediate exit from the procedure: x is evaluated and becomes the return value of the procedure. Execution proceeds after the point where the procedure was invoked.

x may be an expression sequence, i.e., calls such as return(x1, x2, ...) are allowed.

return() returns the void object of type DOM_NULL.

Note that return is a function, not a keyword. A statement such as return x; works in the programming language C, but causes a syntax error in MuPAD.

If called outside a procedure, return(x) just returns x.

Examples

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)

delete mymax:

Example 2

return() returns the void object:

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

delete f:

Example 3

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

x := 1: return(x, y)

delete x:

Parameters

x

Any MuPAD object

Return Values

X.

See Also

MuPAD Domains

MuPAD Functions

Was this topic helpful?