lua-users home
lua-l archive

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


It's true that "for" loops are syntactic sugar, but then if you have
"if" and "goto" so are "while" loops. Syntactic sugar has to be judged
on whether it aids or hinders a human attempting to understand a
program.

On this basis, I don't like general "for" loops. However, I do like
restricted "for" loops as an easily recognizable idiom for simple
loops over a range of integers or the indicies of a table. If the loop
is more complex, I prefer to use an explicit "while" loop as a flag
that I'm going to have to think a little bit more carefully.

If you are going to add "for" loops, then I urge you to restrict
yourself to loops like "for i = 1 to 10 do ... done" and "for i in
table do ... done". I doubt the latter is identical to the proposed
"foreach" function because of scope, although I could be wrong.

"If in doubt, leave it out".

Alan