Filter löschen
Filter löschen

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

26 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Image Analyst
Image Analyst am 25 Okt. 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

Weitere Antworten (0)

Kategorien

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

Tags

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by