Moving to the next iteration of external loop from inside the nested loop

42 visualizaciones (últimos 30 días)
I have a nested loop with 4 for loop and in the internal loop I am doing a condition check and if that condition check is satisfied I want to jump to the next iteration of the external loop.
Something like this;
for yy=1:10
for month=1:12
for day=1:31
for UTM= 0:30:1410
if( condition )
% Move to next iteration of first or external loop( here, go for the next day)
%I want to skip doing the work1 in the continue
end
% some work being done
work1;
end
end
end
end
I used "break" in the if condition but it doesn't work and it has been continued with doing work1

Respuesta aceptada

Image Analyst
Image Analyst el 25 de Oct. de 2021
I believe this should do it:
for yy = 1 : 10
skipIt = false;
for month=1:12
for day=1:31
for UTM= 0:30:1410
if( condition )
% Move to next iteration of first or external loop( here, go for the next day)
%I want to skip doing the work1 in the continue
skipIt = true;
break; % break out of 4th loop.
end
% some work being done
work1;
end
if skipIt
break; % break out of 3rd loop.
end
end
if skipIt
break; % break out of 2nd loop.
end
end
end

Más respuestas (0)

Categorías

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

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by