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

2 次查看(过去 30 天)
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

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by