Exit from several, nested while or for loops with one command
Afficher commentaires plus anciens
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 commentaire
I've seen the "goto" tag! Evil.
Réponse acceptée
Plus de réponses (1)
Apoorva Srivastava
le 14 Juin 2019
Modifié(e) : Apoorva Srivastava
le 14 Juin 2019
0 votes
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!)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!