I received 14 comments on my post about the appropriate name for the "enhanced for loop". I still like my own suggestion of "auto-iterator loop", but apparently no one else did.
There doesn't seem to be a consensus, but "foreach" or variations like "for each" and "for-each" (the space or hypen help to indicate that this is not a keyword) are by far the most popular.
jez gets the award for funniest suggestion. He wants to call it the "five" loop.




David,
Keep in mind that often times those who are dissatisfied make the most noise. I didn't comment mostly because I think auto-iterator is a succinct description. At worst it is a little too technical, and it might scare some green developers, but, you can't please everybody ;).
Be that as it may, I like for-each just fine as well; it leads the developer directly into the english 'talk through' of the code, especially if you replace the colon (':') with 'in'.
"For-each obj in Collection c..."
"Auto-iterator loop" is quite a mouthful. Besides, all loops iterate automatically, even the "non-auto-iterator loops" -- they just don't use an interator. Yes, people are going to describe those loops that are not "auto-iterator loops" as "non-auto-iterator loops" in some contexts :-(
The problem with "auto-iterator loop" is that "auto" is so overloaded in this world. As is perhaps "iterator" (something that iterates?! :-) ).
And what makes you think that someone won't look for the "auto-iterator" keyword? For a novice, it's surely as likely a thing to do as searching for a "foreach" keyword. For an experienced user, and a user using other languages, foreach is obvious.
In principle, I agree with you though. It is not descriptive of it's operational mechanism. A foreach keyword would have been nicer, especially if they beefed up it's syntax to half of what Perl has to offer.
I didn't vote, but 'foreach' seems to be the most intuitive candidate. It reminds me of 'foreach item in iterator', so tells me exactly what each piece of the statement needs to be. And corresponds to Perl's for/foreach.
Auto-Iterator is a bad name because the new foreach loop does not work with iterators [as far as I can tell]. Call it auto-iterating-collection loop if you must :)
I'm with foreach. It's what it should have been called.