lua-users home
lua-l archive

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


On Wed, Dec 31, 2008 at 3:51 PM, Ralph Hempel <rhempel@hempeldesigngroup.com> wrote:
Peter Cawley wrote:
   Note that p (the control variable) is changed in the body
   of the for loop, and this works fine in pure Lua.

Well, it shouldn't. Modifying the control variables of a for loop only affects the copy of that variable within the for loop body - not the variable which is passed back into the iteration function (similarly with a numeric for, the control variable is shadowed within the loop body).

That's what I thought reading the PiL manual, but I was not sure
so I tried it. I was a bit surprised that it worked too.
Except it doesn't work: http://codepad.org/MfGGdS56