MATLAB: How does ‘break’ work

break

Hi, I need to know what happens after "break"? what does the loop skip to? I need it to skip to "for i = 1:50" and start from a new i. Please help me.
for i = 1:50
if a {i,5}(1) <= a{1,4}(1)
b{i,1} = a{1,1};
else
for j = 1:50
if a {i,5}(1) >= a{j,4}(1) && a{i,5}(1) <= a{j+1,4}(1)
b{i,1} = a{j+1,1};
break
end
end
end
end

Best Answer

The "break" statement breaks out of the "innermost" loop that it is inside of. In your code above, it will break out of the for j=1:50 loop and start executing at the next line after the "j loop" end statement. This next statement happens to be the end statement in an else clause. Since there is no "i loop" code after this end statement other than the "i loop" end statement, this break will effectively cause the for i=1:50 loop to skip to the next i also.