lua-users home
lua-l archive

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


Hello,

I've got a question about the so-called "subtle change in the scope of the implicit variables of the for statement and for the repeat statement." (see LuaManual/Imcompabilities with the previous version):

As I found out now, in Lua 5.1 it is no longer possible to increment the implicit variable due to the fact, that it is a local one now.

Lua 5.0:
         while (_step>0 and var<=_limit) or (_step<=0 and var>=_limit) do
           block
           var = var + _step
         end

Lua 5.1:
       while (step > 0 and var <= limit) or (step <= 0 and var >= limit) do
         local v = var
         block
         var = var + step
       end

Unfortunately this avoids the popular procedure to increment and therewith skip an index in a table...


How can/should this be done in Lua 5.1 now??

Cheers,
Eva