Using an or in a while loop.
48 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Matt Merkley
am 23 Jan. 2018
Bearbeitet: Stephen23
am 23 Jan. 2018
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 Kommentar
Akzeptierte Antwort
Walter Roberson
am 23 Jan. 2018
You need && for that rather than || . Your existing code does not exit the loop until both parts are false, which never happens since you do not change ea or es.
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!