フィルターのクリア

conditional statements and while loop

2 ビュー (過去 30 日間)
msh
msh 2014 年 11 月 24 日
コメント済み: msh 2014 年 11 月 24 日
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 件のコメント
msh
msh 2014 年 11 月 24 日
編集済み: msh 2014 年 11 月 24 日
I see. Then this is not what I want. I need ALL conditions to be satisfied in the same time. That is, I need the loop to go on, until ALL three are false. How I should modify the conditions then?
Star Strider
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
Adam 2014 年 11 月 24 日
while (dif1 > tol) || (dif2 > tol) || (dif3 > tol)
should work if you want to carry on until all are false.
  1 件のコメント
msh
msh 2014 年 11 月 24 日
yes, I already did it ! thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by