Jump to content
3186861391

Serious bugs

Recommended Posts

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?

 

 

Share this post


Link to post
Share on other sites

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

 

scr_1553934106.png

Share this post


Link to post
Share on other sites
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

 

scr_1553934106.png

Thank you, enyby. I think I understand.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...