How do I break out of nested loops using the BREAK command in MATLAB 7.7 (R2008b)?
조회 수: 125 (최근 30일)
이전 댓글 표시
I am trying to break out of nested FOR loops using BREAK, but the control returns to the loop immediately above.
채택된 답변
MathWorks Support Team
2009년 6월 27일
This functionality is not availble when using the function BREAK. BREAK will only break out of the loop in which it was called.
As a workaround, you can use a flag variable along with BREAK to break out of nested loops.
flag=0;
for i=1:10
for j=1:5
flag=1;
break
end
if(flag==1)
break
end
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!