Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua For Variable In Range

I can't seem to get this to work. I come from Python, so I tried using the same syntax for the hell of it, but it unsurprisingly wouldn't work:

var = 4

for var in range(2,20) do
print ("var is in range")
      end
like image 470
azonicrider Avatar asked Aug 18 '12 17:08

azonicrider


1 Answers

If you want to test whether a value is in a range, use

if var>=2 and var<=20 then
   print ("var is in range")
end

If you want a loop, use

for var=2,20 do
   print(var)
end
like image 140
lhf Avatar answered Oct 01 '22 15:10

lhf