필터 지우기
필터 지우기

My program stops before checking the while loop condition?

조회 수: 1 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by