return
Return control to invoking script or function
Syntax
Description
return
forces MATLAB®to return control to the invoking program before it reaches the end of the script or function. The invoking program is a script or function that calls the script or function containing the call toreturn
. If you call the script or function that containsreturn
directly, there is no invoking program and MATLAB returns control to the command prompt.
Note
Be careful when you usereturn
within conditional blocks, such asif
orswitch
, or within loop control statements, such asfor
orwhile
. When MATLAB reaches areturn
statement, it does not just exit the loop; it exits the script or function and returns control to the invoking program or command prompt.