www.digitalmars.com         C & C++   DMDScript  

D - Java introduces "enhanced for loops"

reply Jonathan Andrew <Jonathan_member pathlink.com> writes:
I saw an article today that I thought might be of interest to you all,
describing some of the features present in the upcoming Java release.


Of particular interest (or amusement) was their introduction of what they call
"enhanced for loops" aka foreach. The syntax they chose is close to some of that
proposed in this forum-

for(object : collection){


The reason cited for this syntax as opposed to foreach(object in collection) was
to avoid breaking compatibility with existing apps that might use "foreach" and
"in" as keywords. Just thought you might like to check it out.

OT, but reading this article made me appreciate a lot of the design decisions
made in D. Especially the "const" keyword.  

"public static final double SOMENUM = 1.3333333;;

Hmm... just seems a little wordy. =)

May 09 2003
parent "C. Sauls" <ibisbasenji yahoo.com> writes:
I still think we need to settle on a "foreach" syntax and have it
implemented.  Very interesting to see it appear in Java, I'll have to play
with that.

And I absolutely still say we should have key-value pair looping, a la:
    for (anarray; key:value) { ... }

 -- C. Sauls
May 10 2003