Using an or in a while loop.
Mostra commenti meno recenti
I want to have an or statement in my while loop. Eventually I will be incrementing ea as well as iter. But right now it should exit out of the while loop after 100 iterations but it is continuing forever. What is wrong with the or statement? es = .01; imax = 100; iter = 0; ea = es;
while ((ea <= es )|| (iter <= imax) )
iter = iter + 1;
end
disp(iter);
1 Commento
ea = es
means that the first part of the condition ea <= es is always true, and because of the || (or) the while condition will therefore always be true. Is that what you want?
Risposta accettata
Più risposte (1)
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!