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

조회 수: 47 (최근 30일)
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

채택된 답변

Image Analyst
Image Analyst 2021년 10월 25일
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
  댓글 수: 1
Honey
Honey 2021년 10월 26일
Image Analyst ,thank you so much. It was wonderful for me who was thinking about it for two days!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by