MATLAB: Terminating the while if loop

while loop

while abs(dE) > 1e-12
iteration=iteration+1;
E_old = E;
E = M+(ecc(1)*sin(E)); %eccentric anomaly
dE=E-E_old;
if iteration==1000
warndlg('iteration cannot be converged ', 'Error!', 'modal')
end
end
How can I modify above code to terminate the while loop when iteration exceeds 1000?

Best Answer

I would add a break or return in your if block:
if iteration>=1000
warndlg('iteration cannot be converged ', 'Error!', 'modal')
return
end