MATLAB: How to end a for loop with an if or while loop

helpifloopswhile

H

Best Answer

Hello,
Yes you can end a for loop early using break,
for N = 1:n
% Do something
if (some condition is met)
break
end
end
This will end the for loop early when the condition is met.
Hope this helps!
Related Question