lua-users home
lua-l archive

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

On 9/27/07, Eva Schmidt <> wrote:
How can/should this [messing with the for index] be done in Lua 5.1 now??

By reverting to an explicit "" 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.