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!