✓ Accepted answer
This is a problem with numbers on our computer not having infinite precision. When you write 0.1, it doesn't actually store is as "one tenth". It stores it as a base-2 approximation of 0.1, which is something like this:
0.10000000000000000555111512312578
That means the number you get after you get just around 1 is about 20 * .00000000000000000555111512312578 under 1, so it declares the loop over.
The simplest solution is to use integers, and divide on the inside:
for I = 50, 10, -2 do
local i = I * 0.1
end
Depending on what you are doing, other options might make sense. For example, if you're doing something like an animation, you could not worry about the for loop altogether and just use the time:
local start = tick()
local duration = 4
while tick() < start + duration do
local time = tick() - start
local progress = time / duration
wait()
end
1 comment
makes sense :) dang .111111111 numbers