repeating the loop until condition is met

6 visualizaciones (últimos 30 días)
NETHRAVATHI S
NETHRAVATHI S el 23 de Abr. de 2021
Comentada: DGM el 24 de Abr. de 2021
Hello,
I have a prog, in which I have to repeat the function until a condition is met.
I used while loop, but it is running only once and coming out of the loop.
My code looks somewhat like this. It is a lengthy prog, hence just posting the gist.
iteration=0
while 1
calling a function which will give me an array
the returned array is checked to meet a specific requirement
if the requirement is not met, then call the function again.
iteration=iteration+1;
end
  4 comentarios
per isakson
per isakson el 24 de Abr. de 2021
Editada: per isakson el 24 de Abr. de 2021
More standard
thinghappens = false;
while not( thinghappens )
% do stuff
end
DGM
DGM el 24 de Abr. de 2021
I can agree to that, but I was hoping that the obvious hint would be that the two can be combined.
while ~normalexitcondition
% do stuff
if abnormalexitcondition
warning('oh no!')
break;
end
end

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by