Do we need "foreach"?

Robert Fraser fraserofthenight at gmail.com
Mon Apr 28 03:24:43 PDT 2008


Bill Baxter wrote:
> Just started wondering why we really need the foreach keyword.
> 
> These two
> 
> for( x ; y ; z )
> 
> for( x ; y )
> 
> do no seem to be ambiguous to me.  You do need some lookahead, but I 
> think D has some constructs like that already.
> 
> If we're looking to get rid of keywords it seems like a candidate.  I 
> already mistakenly type "for" when I mean "foreach" fairly often.
> 
> --bb

Java's solution is to use a colon in place of the semicolon.

for(x : y)



More information about the Digitalmars-d mailing list