exiting a loop

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

类别

在 帮助中心 和 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