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 についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by