exiting a loop

조회 수: 1 (최근 30일)
Bahareh
Bahareh 2011년 10월 29일
Hello all,
I have a while loop in which
while abs(a-b)>=delta
rest of code
end
Sometimes the condition of this while loop is not satisfied and my program gets stuck in the loop; is there any way that I can specify the number of iterations such that after this specified value, my program exits the loop?
Many thanks in advance.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 10월 29일
k = 0;
while abs(a-b)>=delta | k < 1e3
....
k = k + 1;
end
  댓글 수: 1
Bahareh
Bahareh 2011년 10월 29일
Thanks but instead of | I put &&, then it worked.

댓글을 달려면 로그인하십시오.

추가 답변 (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