[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Numeric for loop: Changing control variable REALLY dangerous?
- From: Mason Bogue <scythe+lua@...>
- Date: Mon, 12 Dec 2022 12:47:05 -0500
It may be helpful to remember in the context of the code aesthetics that Lua enforces almost no restrictions on where statements go. For instance, it is perfectly legal to write this:
do local i = 0 while i < 10 do i = i + 1
print("Not a for loop!")
-- loop body statements
if you really want something that "looks like a for loop" with the desired behavior. Of course, the "end end" is a bit ugly.
- It is possible that the next Lua version will operate directly with
the loop variable, without any internal copy.
- It is possible that, in the next Lua version, the loop control
variable will be implicit declared as <const> to make the above change
The second item would be a good idea, for both the numeric and generic for loops.