conditional statements and while loop
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Star Strider
2014-11-24
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.
采纳的回答
Adam
2014-11-24
while (dif1 > tol) || (dif2 > tol) || (dif3 > tol)
should work if you want to carry on until all are false.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!