Hi, I am writing code to break out of loop. I have several loops, including nested loops. If I use break in a if command, it will jump out of all loops, or the very nearest loop(say only one loop)?
for i=1:10 for j=1:10 f(x)=... if f(x)>10 ... elseif f(x)<5 break; .... end end end
If f(x)<5 for some i=2 and j=3; then break will jump out of loop, go to i=3, j=1 or i=2 j=4?
No products are associated with this question.
I think only the loop in which the break occurs is broken out of..
for ii=1:5 ii for jj=1:6 jj if ii==3 && jj==4 disp('broken here') break;
end end end
Play games and win prizes!Learn more