On Wednesday, 21 October 2020 at 12:06:00 UTC, drug wrote:
There are two other way:
...
    // using foreach
    foreach (i; 0..a.length)
        write(a[i], ", ");
...

Yes you can use foreach, but in this case will not act the way the OP wanted. In his for loop example the "i" is incremented by 2: "i+=2".

So to perform what OP want with foreach it should be:

    foreach (i,j;a){
        if(i%2==0){ write(j, ", ");}
    }

By the way it's possible to set a "step" value for "foreach"?

Matheus.

Reply via email to