[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: "subtle change" in for loop
- From: Fabien <fleutot+lua@...>
- Date: Thu, 27 Sep 2007 17:15:04 +0200
On 9/27/07, Eva Schmidt <email@example.com> wrote:
How can/should this [messing with the for index] be done in Lua 5.1 now??
By reverting to an explicit "while...do...end" loop :)
Which is not a bad thing IMO: a "for" loop is only marginally shorter to write than a "while" loop. Its interest is documentary: when I read some code with a "for" loop, I know immediately that it will iterate on every index value (unless it's interrupted with a "break"). Now if you write your skipping "for" as a "while" loop (as you now have to), when reading it I'll know that some special stuff will happen to the index: that's what the "while" tells me, as a hint for code readers.
Code must be optimized for reading, not for writing.