[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: for loops
- From: alan@... (Alan Watson)
- Date: Wed, 29 Oct 1997 11:53:46 -0600
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
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".