lua-users home
lua-l archive

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


> hi list and Roberto :-)
> 
> the PiL says you should never change the for iteraotr variable, but I
> can not found this in reference, so I want to ask whether this
> variable is just a normal variable? that is, if I change its value,
> except the value of iterator will reset before the next loop is
> executed, what else behavior will happen? or is this a undefined
> hebahvior?
> 
> regards,
> Xavier

If PiL does not agree with the manual, follow the manual.

According to the manual, the visible iterator variable is a regular
local variable that gets a copy of the "real" iterator variable; so, you
may assign to it, but that assignment does not affect the loop.

Nevertheless, PiL is partially correct in that it is not a good practice
to rely on this specific behavior. Certainly other people reading your
code (or even you after some time) will have doubts about what is going
on.

-- Roberto