How to break a for loop but then continue with the rest of code

9 ビュー (過去 30 日間)
Arsal15
Arsal15 2016 年 2 月 18 日
コメント済み: Arsal15 2016 年 2 月 18 日
Hi I have this situation and I have done coding but my code don't break when all nodes get data.
Can you guide me.

採用された回答

Jos (10584)
Jos (10584) 2016 年 2 月 18 日
Use break
for k=1:100,
if rand < 0.2
disp('Break out of for loop')
break
end
end
disp(k) % almost never reached 100
  1 件のコメント
Arsal15
Arsal15 2016 年 2 月 18 日
編集済み: Arsal15 2016 年 2 月 18 日
Do you have time to have a look of my code.?
Because I have tried same but I m using breakpoints but not skipping it.

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

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2016 年 2 月 18 日
編集済み: Fangjun Jiang 2016 年 2 月 18 日
Use continue or break to control the for-loop.
help continue
help break
  1 件のコメント
Arsal15
Arsal15 2016 年 2 月 18 日
Thanks for your kind reply Fangjun Jiang

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

カテゴリ

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