exiting a loop

1 visualizzazione (ultimi 30 giorni)
Bahareh
Bahareh il 29 Ott 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.

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by