Return control to invoking function
return
return
forces MATLAB® to return control
to the invoking function before it reaches the end of the function.
The invoking function is the function that calls the script or function
containing the call to return
. If you call the
function or script that contains return
directly,
there is no invoking function and MATLAB returns control to the
command prompt.
Be careful when you use return
within conditional
blocks, such as if
or switch
,
or within loop control statements, such as for
or while
.
When MATLAB reaches a return
statement, it
does not just exit the loop; it exits the script or function and returns
control to the invoking function or command prompt.