5 is optional 5:
t=0 while t<5: #currently loop runs for 10 seconds print "in loop",t, repr(t) if (t<5): print "true" t=t+0.1
produces
in loop 0 0 true in loop 0.1 0.1 true in loop 0.2 0.2 true in loop 0.3 0.30000000000000004
[...]
in loop 4.8 4.799999999999999 true in loop 4.9 4.899999999999999 true in loop 5.0 4.999999999999998 true
0.1 cannot be represented exactly in binary format.
[Ah, I just noticed that instead of 0.1, instead of 0.1 I used 0.1. Well, this is the same problem.]
Two links "how floating point works": classic and gentler .
source share