conditional statements and while loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I have the following while loop
while (dif1 > tol) && (dif2 > tol) && (dif3 > tol)
procedure
end
I want all the conditions to be simultaneously satisfied. However, when I execute the code, the second condition dif2 > tol is not satisfied although the algorithm stops.
what I am doing wrong here ?
3 Kommentare
Star Strider
am 24 Nov. 2014
The double operands ‘&&’ and ‘| |’ ‘short circuit’ the comparisons. See: Logical Operators: Short-Circuit && | |. If the first is false, it will not evaluate any of the others.
Akzeptierte Antwort
Adam
am 24 Nov. 2014
while (dif1 > tol) || (dif2 > tol) || (dif3 > tol)
should work if you want to carry on until all are false.
Weitere Antworten (0)
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!