MATLAB中return和break

return:

RETURN Return to invoking function.
RETURN causes a return to the invoking function or to the keyboard.
It also terminates the KEYBOARD mode.

Normally functions return when the end of the function is reached.
A RETURN statement can be used to force an early return.

Example
function d = det(A)
if isempty(A)
d = 1;
return
else
...
end

 

break:

BREAK Terminate execution of WHILE or FOR loop.
BREAK terminates the execution of FOR and WHILE loops.
In nested loops, BREAK exits from the innermost loop only.

BREAK is not defined outside of a FOR or WHILE loop.
Use RETURN in this context instead.

 

原文地址:https://www.cnblogs.com/wangduo/p/5269038.html