How to use continue when I have both for and while loop
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Mikie
il 17 Giu 2018
Risposto: Walter Roberson
il 17 Giu 2018
Hi, I want to tell Matlab to skip the rest of the instructions and begin the next iteration "for" when the solution of X(1) is Nan. I wrote the following code but that continue in the loop "while". How can I tell MATLAB to go to the next iteration under the loop "for"?
for i = 1:100
while error < 10
solve equations for X(1) and X(2)
if isnan(X(1))
continue
end
error = X(1) - X(2)
end
end
Please help me. Thank you.
0 Commenti
Risposta accettata
Walter Roberson
il 17 Giu 2018
Change the "continue" to "break". That will cause it to exit the "while" loop.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!