MATLAB: How to terminate the loop

terminate the loop

I want to terminate the loop. Condition is satisfying at i = 96, but loop is still running till the end.
after the termination, i want to know the value of i.
point_load(1) = 0;
for i = 1 : 100
point_load(i + 1) = point_load(i) + 1;
PL_BM(i) = point_load(i) * beam_length / 4;
PL_BM = repelem(PL_BM(i),n);
failure_domain_BM = ( RV_BM - PL_BM(i) ) < 0;
p_f_BM = sum(failure_domain_BM (:) == 1) / n;
if p_f_BM == 1
break
disp(point_load(i+1))
end
end

Best Answer

Due to floating-point error, it may be that the condition
if p_f_BM == 1
is not exactly met. With floating-point numbers, it's better to check for equality within some tolerance. Try something like
if abs(p_f_BM-1) < tol
for some appropriately small value of tol.