foreach/iota countdown
Timon Gehr
timon.gehr at gmx.ch
Mon Feb 17 11:30:38 PST 2014
On 02/17/2014 08:22 PM, simendsjo wrote:
> Should the following two uses be a compile-time error?
> foreach(i; 10 .. 0) // Never executes
>
> foreach(i; iota(10, 0)) // .. neither does this
>
> I would like the second to either be a compile-time error or
> automagically use a negative step.
>
> So we need to use a negative step in iota() or use a for loop
> foreach(i; iota(10, 0, -1)) // as expected
The parameters can be runtime values. Auto-magically using a negative
step would hence be a bad idea.
More information about the Digitalmars-d-learn
mailing list