Advance for loop variable if condition met

조회 수: 4 (최근 30일)
Kaden
Kaden 2018년 7월 12일
답변: dpb 2018년 7월 12일
Hi,
Is there a method to exit a for loop if a condition is met? For instance, looking at the code below, if the ArrayOne value equals the ArrayTwo value, I would like to automatically jump to the next K value without finishing the j loop. Is this possible?
In the code I am working on, there is a lot of data that is being processed which is taking a long time due to the code checking for a match for all the j values, even if one was found already.
for k = 2:12
for j = 1:10000
if(ArrayOne(1,k) == ArrayTwo(3,j))
"Do Stuff"
Jump to next k Value, restart j loop
end
end
end
Thanks for the help!

답변 (1개)

dpb
dpb 2018년 7월 12일
doc continue
doc break
doc for
There's also always
doc while
if a counted for isn't really the bestest construct...

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by