Hi. I am experiencing a strange behavior in this simple script:
% CASE 1 - COMPUTES CORRECTLY
m1=1;while m1<4.80 m1=m1+0.1;enddisp(m1);% CASE 2 - DOES NOT COMPUTE CORRECTLY
m2=1;while m2<4.90 m2=m2+0.1;enddisp(m2);
I obtain m1 = 4.8, as expected. However, I obtain m2 = 5.0, which implies the loop in CASE 2 has gone on for one iteration too many. Any idea why this might be happening? Is it a precision-related issue? I'm afraid I must be missing something very silly. Thank you for your help.
Best Answer