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

45 ビュー (過去 30 日間)
Honey
Honey 2021 年 10 月 25 日
コメント済み: Honey 2021 年 10 月 26 日
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 Center および File ExchangeLoops 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