has use of "break" changed recenty?

12 ビュー (過去 30 日間)
Robert
Robert 2016 年 10 月 11 日
コメント済み: Rik 2020 年 12 月 13 日
I have script which has functioned well under previous version of MatLab, recently updated the software to 2016a, and now get following error when running script.
Error: 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.
Has the use of the break function changed?
  4 件のコメント
Adam Danz
Adam Danz 2020 年 12 月 13 日
@Rik , what time machine did you use to access this documentation? Your comment is dated Dec-2020 but the online documentation prior to 15b was removed over the summer. Is this documentation a local copy?
Rik
Rik 2020 年 12 月 13 日
Yes, all of this is from local copies (only some of these required a VM). So unfortunately the time machine in question is metaphorical. The Wayback Machine will probably not have many of these.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2016 年 10 月 11 日
編集済み: Star Strider 2016 年 10 月 11 日
It has, several versions ago. If you want to stop a script outside of a loop, use return instead of break. It does the same thing, and won’t throw an error.
To wit:
fprintf(1, 'Before ''return''\n')
return
fprintf(1, 'After ''return''\n')
EDIT Added demonstration code snippet.
  3 件のコメント
Star Strider
Star Strider 2016 年 10 月 11 日
My pleasure.
If my Answer helped solve your problem, please Accept it.
emmanuel vergara
emmanuel vergara 2020 年 12 月 10 日
Great tip, thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by