lua-users home
lua-l archive

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


> 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.

Just a remark: this change in the behavior of the implicit variable
is not directly related to the change in its scope. Since Lua 5.0 you
should not use that trick of changing the implicit variable. From Lua
5.0 manual:

  * The behavior is undefined if you assign to var inside the block.


The change in scope means that, conceptually, at each new iteraction
'var' is a new variable (from the point of view of closures created
inside the loop).

-- Roberto