I have a while
loop in which I have two for
loops. I have a condition in the innermost for
loop. Whenever that condition is satisfied I want to exit from both the two for
loops and continue within the while
loop:
while (1)
for x=1:20
for y=1:30
if(condition)
end
end
end
end
Does Matlab have something like a labeled statement in Java, or is there another way to do this?
One ever so slightly more elegant way than Luis Mendo's. ;-)
while (1)
for x=1:20
for y=1:30
quit = (condition);
if quit
break;
end
end
if quit
break;
end
end
end
Only slightly more elegant than A.Donda's answer (avoids testing the condition twice):
while 1
for x=1:20
for y=1:30
quit = 0;
if (condition)
quit = 1;
break;
end
end
if quit
break;
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With