shorter foreach syntax - C++0x range-based for

Nick Treleaven nospam at example.net
Mon Nov 1 08:59:11 PDT 2010


On Mon, 01 Nov 2010 10:09:17 -0400, Gary Whatmore wrote:

>> I think this is better:
>> 
>> for (ref x : array)
>>   x *= 2;
>> 
>> Apart from being 4 chars shorter, I think it looks more natural using
>> the ':' instead of ';'. A lesser benefit is it allows reuse of the
>> 'for' keyword, making the 'foreach' keyword unnecessary.
>> 
>> Maybe this would be acceptable for D?
> 
> No, 1) it's too late to change it.

I don't see a technical reason why foreach, the above for syntax and 'C' 
for syntax can't all be supported.

> 2) the syntax comes from Java.

Perhaps if C++0x does add this and Java already has it this makes more of 
an argument for D supporting it?


More information about the Digitalmars-d mailing list