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일

0 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2011년 10월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by