On Sunday, 9 August 2015 at 16:42:16 UTC, Jay Norwood wrote:
The i+3 initialization is just so you can see that v is the Arr member (not the index) in the other loops.

import std.stdio : writeln;
void main()     {
        immutable a=5;
        int[a] Arr;
        foreach(i, ref v; Arr)      {
                v = i+3;
        }
        foreach( ref v; Arr)      {
                writeln(v);
        }
        foreach( c; Arr)      {
                writeln(c);
        }
}

Oooh... I like how this works

import std.stdio : writeln, readf;
void main()     {
        immutable a=5;
        int[a] Arr;
        int nim;
        foreach(num, ref nem; Arr)      {
                readf(" %s", &nem);
        }
        foreach(num; Arr)      {
                writeln(num);
        }
}

Reply via email to