3186861391 Posted March 30, 2019 Share Posted March 30, 2019 As fallows: i=5 while i~=6 do if i<7 then i=i+0.1 end print(i) gg.sleep(20) end Running it will loop on forever, and if it is interrupted then "i" will end up with 7.1 What went wrong? Link to comment Share on other sites More sharing options...
Administrators Enyby Posted March 30, 2019 Administrators Share Posted March 30, 2019 You try compare float number for equality. i~=6 i can be never equal 6 because it is float. It can be 6.000000000001 for example. And your loop endless. Never compare floats by equality. [added 2 minutes later] Let see: https://www.lua.org/cgi-bin/demo Link to comment Share on other sites More sharing options...
3186861391 Posted March 30, 2019 Author Share Posted March 30, 2019 27 minutes ago, Enyby said: You try compare float number for equality. i~=6 i can be never equal 6 because it is float. It can be 6.000000000001 for example. And your loop endless. Never compare floats by equality. [added 2 minutes later] Let see: https://www.lua.org/cgi-bin/demo Thank you, enyby. I think I understand. Link to comment Share on other sites More sharing options...
Question
3186861391
As fallows:
i=5
while i~=6 do
if i<7 then i=i+0.1 end
print(i)
gg.sleep(20)
end
Running it will loop on forever, and if it is interrupted then "i" will end up with 7.1
What went wrong?
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.