About foreach loops
Caligo
iteronvexor at gmail.com
Wed Jun 15 09:08:29 PDT 2011
On Wed, Jun 15, 2011 at 10:34 AM, so <so at so.so> wrote:
> On Wed, 15 Jun 2011 18:23:55 +0300, Caligo <iteronvexor at gmail.com> wrote:
>
>> This should be a compile time error:
>>
>> foreach(i; 0..10){
>> i += 1;
>> write(i, " ");
>> }
>>
>> This should be legal.
>> foreach(ref i; 0..10){
>> i += 1;
>> write(i, " ");
>> }
>>
>> Is that the general consensus here?
>
> They both should be legal, the first one is value, the second one is
> reference.
>
A reference to what exactly?
Does this make any sense:
for(ref int i; i < 10; ++i){
i += 1;
write(i, " ");
}
It doesn't even compile.
'foreach(i, 0..10){ }' is syntactic sugar for 'for(int i = 0; i < 10;
++i){ }', is it not?
More information about the Digitalmars-d
mailing list