当前位置:   article > 正文

Matlab break error_a break statement may only be used within a loop o

a break statement may only be used within a loop or switch
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
  • 1
  • 很多老版本可以用,但是其他版本替换为return
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.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

https://ww2.mathworks.cn/matlabcentral/answers/306791-has-use-of-break-changed-recenty

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/909180
推荐阅读
  

闽ICP备14008679号