exiting a loop

1 Ansicht (letzte 30 Tage)
Bahareh
Bahareh am 29 Okt. 2011
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.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 29 Okt. 2011
k = 0;
while abs(a-b)>=delta | k < 1e3
....
k = k + 1;
end
  1 Kommentar
Bahareh
Bahareh am 29 Okt. 2011
Thanks but instead of | I put &&, then it worked.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by