Starting a Loop over again
조회 수: 31 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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
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
2012년 12월 20일
Ah, yes, that is a plausible interpretation of the question. Not what I would have guessed, but plausible.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!