✓ Accepted answer
I added an extra print to your code for testing purposes.
a = 0
repeat
a = a + 0.1
wait(0.1)
print(a, a == 1)
until a == 1
Alright, so now it will both print a and if a equals 1.
Take a look at the output I get:
0.1 false
0.2 false
0.3 false
0.4 false
0.5 false
0.6 false
0.7 false
0.8 false
0.9 false
1 false
1.1 false
...
How is this possible? It prints as 1, but at the same time states it doesn't equal 1.
Well, this is the annoying thing about comparing numbers. I can't seem to find the wiki article that talks about it, but basically a doesn't equal 1.
It's much more likely to equal something like 1.0000041545. This would cause the comparison to be false.
This is why, when comparing numbers, it's much better do use >= and <= for 'greater than or equal to' and 'less than or equal to' respectively. This will allow for numbers slightly greater or slightly less than the number you're comparing it to, so it will be true even with weird decimals.
a = 0
repeat
a = a + 0.1
wait(0.1)
print(a)
until a >= 1
1 comment
What exactly isn't working about it?