I used Octave to write this code.
x=0.0;
while (x~=1.0)
x=x+0.1;
fprintf('x=%20.18f\n',x)
pause
endwhile
I want to stop the code when x
is equal to 1
.
So, I put some code like this
x=0.0;
while (x~=1.0)
x=x+0.1;
fprintf('x=%20.18f\n',x)
if abs(x-1)<(eps/2),
print(x)
endif
pause
endwhile
But it did not work, and show numbers infinitely. How can I write a code to stop this code when x
is equal to 1
?