My program stops before checking the while loop condition?

3 ビュー (過去 30 日間)
amine&&
amine&& 2016 年 6 月 30 日
コメント済み: amine&& 2016 年 7 月 1 日
My program stops before checking the while loop condition
while (c1> 1 * 10 ^ -2) && (c2> 1 * 10 ^ -1) && (iter <= 1) {}
when the program stops I have the following values: c1=0.012, c2=0.074 and iter = 1.
Thanks.

採用された回答

Walter Roberson
Walter Roberson 2016 年 6 月 30 日
c2> 1 * 10 ^ -1 is not true for c2 = 0.074
  3 件のコメント
Walter Roberson
Walter Roberson 2016 年 6 月 30 日
You used && so the condition is only true if all parts of it are true. One part of it is false, so the entire condition is false. If you want to execute the body of the loop if any of the conditions are true, then use || instead of &&
amine&&
amine&& 2016 年 7 月 1 日
Thanks for your help Roberson.

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

その他の回答 (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