[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Can I change the for iteraotr variable in a loop?
- From: Patrick Rapin <toupie300@...>
- Date: Wed, 16 May 2012 09:29:05 +0200
To my knowledge, it is in theory undefined behavior, so shall not be done.
In practice, an iterator variable acts as regular local variables that
could be assigned to.
But this *does not* affect the loop, as if the variable holds *a copy*
of the real iteration state.
Examples:
> for i=1,3 do i=i*2; print(i) end
2
4
6
> for k,v in pairs(table) do k=k..k; print(k,v) end
maxnmaxn function: 003CD800
packpack function: 0041DDA0
concatconcat function: 0041DBA0
insertinsert function: 0041D820
sortsort function: 0041E520
removeremove function: 0041D950
unpackunpack function: 0041DE80