lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

>> for i=1,getn(l) do
>You can write:
>ln = getn(list)
>for i = 1, ln do
>  local v = list[i]

No need for this.
In a "for" loop, the limits are computed before the loop starts.
The manual says so:

A for statement like 
       for var = e1 ,e2, e3 do block end
is equivalent to the code: 
         local var, _limit, _step = tonumber(e1), tonumber(e2), tonumber(e3)
         if not (var and _limit and _step) then error() end
         while (_step>0 and var<=_limit) or (_step<=0 and var>=_limit) do
           var = var+_step

In C it's different. :-)