lua-users home
lua-l archive

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


Hi,

Asko Kauppi wrote:
> Lua 5.0 refman says:
> 
> "The behavior [of the iterative for statement] is undefined if you 
> assign to var_1 inside the block."

This has already changed in Lua 5.1. You get a private copy of the control
variable inside the loop. Modifying it is safe now.

$ lua50 -e 'for k,v in pairs({1,2,3}) do print(k,v); k="foo" end'
1	1
lua50: invalid key for `next'

$ lua51w4 -e 'for k,v in pairs({1,2,3}) do print(k,v); k="foo" end'
1	1
2	2
3	3

Ditto for loops with counters.

Bye,
     Mike