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.

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 29 de Oct. de 2011

0 votos

k = 0;
while abs(a-b)>=delta | k < 1e3
....
k = k + 1;
end

1 comentario

Bahareh
Bahareh el 29 de Oct. de 2011
Thanks but instead of | I put &&, then it worked.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 29 de Oct. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by