MATLAB Answers

Starting a Loop over again

145 views (last 30 days)
David Koenig
David Koenig on 19 Dec 2012
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

Answers (1)

Walter Roberson
Walter Roberson on 20 Dec 2012
Edited: Walter Roberson on 20 Dec 2012
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 Comments
Walter Roberson
Walter Roberson on 20 Dec 2012
Ah, yes, that is a plausible interpretation of the question. Not what I would have guessed, but plausible.

Sign in to comment.

Tags

Products

Community Treasure Hunt

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

Start Hunting!