How to break a while loop to another one?

2 ビュー (過去 30 日間)
Mustafa Sami
Mustafa Sami 2021 年 4 月 13 日
コメント済み: Mustafa Sami 2021 年 4 月 19 日
Dear all,
I have 3 while loops inside each other. I want to break from the most inner one to the one before it.
For example:
while count_A >100
A = X
while count_B >10
B = X
while count_C >5
C = X
break
end
end
end
The break I show above will break the "while count_C >5" loop and start again from the first "while count_A >100",
but I want the loop to go the while count_B >10 once it breaks.
Any idea how to control this?

採用された回答

Walter Roberson
Walter Roberson 2021 年 4 月 13 日
編集済み: Walter Roberson 2021 年 4 月 13 日
while outer test
outer stuff
quit_middle = false;
while middle test
middle stuff
while inner test
inner stuff
if some inner reason
quit_middle = true;
break;
end %inner if
end %inner while
if quit_middle; break; end
end %middle while
end %outer while
  1 件のコメント
Mustafa Sami
Mustafa Sami 2021 年 4 月 19 日
Thank you very much Walter.

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

その他の回答 (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