fredpiston84 / luaforwindows

Automatically exported from code.google.com/p/luaforwindows
0 stars 0 forks source link

if statement in a loop #62

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
for i=1,50,1
do
   if i == 25 then
   print(i) 
   end
end

This script (which is at above) has to print 25 when "i" reach 25.
and it does print.

BUT the script (which is at below) has to ALSO print 25 when "i" reach 25. but 
it doesnt!!!   I am new to this , please let me know what is wrong. you may 
disregard if this is known issue

for i=1,50,0.1
do
   if i == 25 then
   print(i) 
   end
end

Original issue reported on code.google.com by nitro555 on 26 Aug 2012 at 12:40

GoogleCodeExporter commented 9 years ago
The For-statement can only use steps that are whole numbers. So you can't use 
steps like 1.5 or 0.1 in your case. If you want the loop to run longer, you 
must increase the limit. In your case, you should increase the limit to 500, 
the variable you want to reach to 250 (and maybe you should change print(i) to 
print(25) if you still want the program to print that number) and set the step 
back to 1.

Original comment by timberin...@gmail.com on 7 Sep 2012 at 9:39

GoogleCodeExporter commented 9 years ago
this has nothing to do with luaforwindows, but is your usage of lua itself

for i=1,50,0.1
do
   if math.abs(i-25)<0.001 then -------
   print(i)
   end
end

Original comment by d.ledent...@gmail.com on 23 Oct 2012 at 7:44