MATLAB: While loops

while loops

First time posting. Excuse if i do not post correctly. My problem is with a while loop. I created my self a short while loop test just to see how it works. i run it and it does what i want. that is to say increase mx by 1 until it hits 3, and then when sum is equal to summ, it performs a. here is what i wrote.
mx=1;
while mx<3.0 mx=mx+1; sum=mx*2; summ =4; if (sum==summ) break a=2*sum end end
My problem is that when i increase mx by 0.1 matlab does not perform the if statement. I know sum and summ will be equal at some point but matlabd never performs a. Any help? thank you.

Best Answer

Also, you might find Cleve's article interesting.
.
.
.
mx=1;
tol = 1e-8;
while mx<3.0
mx=mx+1;
sum=mx*2;
summ =4;
if abs(sum-summ)<tol
a=2*sum
break
end
end