[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: "subtle change" in for loop
- From: roberto@... (Roberto Ierusalimschy)
- Date: Thu, 27 Sep 2007 13:21:27 -0300
> 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
* 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).