Starting a Loop over again

34 次查看(过去 30 天)
David Koenig
David Koenig 2012-12-19
If I am in a while/end loop and I find that I have a mistake and want to get out of the loop and start the loop over again, how do I do it?
I have tried break but that gets me out of the loop and positions me to go on the next part of the script. Instead, I want to go back and start the loop over again.
Thanks,
Dave

回答(1 个)

Walter Roberson
Walter Roberson 2012-12-20
编辑:Walter Roberson 2012-12-20
continue
as in
c = 0;
while c <= 100
I_detected_an_error = rand() < 0.07;
if I_detected_an_error
disp('LART!')
continue;
end
c = c + 1;
end
  4 个评论
Image Analyst
Image Analyst 2012-12-20
I think you need to set c = 1 just before the continue if you really want to start the loop all over again from the beginning, instead of just continuing with the next iteration.
Walter Roberson
Walter Roberson 2012-12-20
Ah, yes, that is a plausible interpretation of the question. Not what I would have guessed, but plausible.

请先登录,再进行评论。

类别

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