Снято с Google:
What is floating point error?
The most common situation is illustrated by the decimal number 0.1.
Although it has a finite decimal representation, in binary it has an
infinite repeating representation. Thus when = 2, the number 0.1 lies
strictly between two floating-point numbers and is exactly representable
by neither of them.
Итак, заполнив ваш пример из 9, ваша петля, вероятно, выглядела так:
num = 0; add 0.0001 -> num is now 0.000099999999
add 0.0001 -> num is now 0.000199999999998
add 0.0001 -> num is now 0.000299999999997
etc...
add 0.0001 -> num is now 2.9999999999953667
add 0.0001 -> num is now 3.000099999994321
Итак, ваше точное сравнение с 3 не будет соответствовать.