I don't know whether this will help but when I was learning C++ we learned that decimals are actually somewhat deceptive and thus you cannot perform straight maths with them sometimes (I don't know whether this also applies to DB, this is an old DOS based C++).
For example 47 converted to decimals isn't actually 47.00000000 but rather 46.99999999999 and just rounded off. So if you said
deci# = 40.5 + 46.5
WHILE deci#/47 >< 1
ENDWHILE
Print "they are the same"
it would cause an infinite loop by those measures. I haven't tested that but in another case, perhaps yours, it might apply. I don't know whether that helps but you can't say I didn't try