foreach on interval index by ref increment

F i L witte2008 at gmail.com
Sun Jan 22 22:13:19 PST 2012


Marco Leise wrote:
>
> 	foreach (i; 0 ... 9, +2)
>

This syntax looks nice. In fact it could replace 
"foreach_reverse" simply by specifying a negative step value: 
foreach (i; 9 .. 0, -1)


> also nice would be:
>
> 	foreach (i; 9 ... 0)
>
> The alternative:
>
> 	foreach_reverse(i; 0 .. 10)
>
> is really hard on the human brain :D

Wouldn't this require additional runtime checks? If "foreach (i; 
9 .. 0)" was sugar for "foreach (i; 9 .. 0, -1)" in cases where 
each range value could be determined at compile time that would 
make sense. Otherwise I'd rather have my brain do a bit more work 
in these cases over slowing down loops everywhere.




More information about the Digitalmars-d mailing list