Exit from several, nested while or for loops with one command
이전 댓글 표시
Hello Is there an easy way to quit nested while loops with a command?
For example:
while condition1 = true
...
while condition2 = true
...
while condition3 = true
...
if condition4 = true
leave all while loops and continue with 'command1';
end
end
end
end
command1;
I know that in nested loops, 'break' exits only from the loop in which it occurs. Control passes to the statement that follows the end of that loop.
댓글 수: 1
I've seen the "goto" tag! Evil.
채택된 답변
추가 답변 (1개)
Apoorva Srivastava
2019년 6월 14일
편집: Apoorva Srivastava
2019년 6월 14일
0 개 추천
If you want to stop the program completely but not close MATLAB, you can just use return. (Note: It can be used even without a function!)
카테고리
도움말 센터 및 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!