赞
踩
A BREAK may only be used within a FOR or WHILE loop, and then only within the same file as its corresponding FOR or WHILE statement
R2015a/R2018a/R2020b:
break is not defined outside a for or while loop. To exit a function, use return.
ML7.1 (R14SP3, released September 2005)/R2010a/R2011a:
break is not defined outside a for or while loop. Use return in this context instead.
That sounds more like it is discouraging, implying with the word 'instead' that this is a change. Let's look back a little further.
ML6.5 (R13, released July 2002):
break is not defined outside of a for or while loop. Use return in this context instead.
OK, so the word 'of' was removed in later releases. Not much of a change, if you ask me.
ML6.1 (R12.1, released June 2001):
If you use break outside of a for or while loop in a MATLAB script or function,
break terminates the script or function at that point.
If break is executed in an if, switch-case, or try-catch statement, it terminates
the statement at that point.
So finally we found it: this behavior was last properly documented when there was support for Windows 95.
https://ww2.mathworks.cn/matlabcentral/answers/306791-has-use-of-break-changed-recenty
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。