With any DO UNTIL loop, it is possible that it never ends because the UNTIL condition never becomes true. In your case, this condition might never become true: (n < 0.001)
One way to guard against it is to allow two ways for the loop to end:
do k=1 to 100000 until (n < 0.001);
If the loop iterates 100,000 times, it will end regardless of the value of n. Your subsequent statements might have to allow for the possibility that n > 0.001. The loop will end before 100,000 iterations if the UNTIL condition becomes true.
Good luck.