Foreach Range Statement

Xinok xnknet at gmail.com
Sun Jul 22 16:54:59 PDT 2007


I'd like to suggest my own design for this. I originally posted it to 
the unofficial wish list to see how many votes it would get:
http://all-technology.com/eigenpolls/dwishlist/index.php?it=142

The arguments are basically the same as the range / xrange functions in 
Python.

The only thing my design doesn't provide is foreach_reverse. Python 
automatically reverses provided the values are correct (xrange(10, 0, 
-1)), but this would cause a small overhead in the loop.


for i(100)
foreach(i; 0..100)
for(int i = 0; i < 100; ++i)

for i(100, 200)
foreach(i; 100..200)
for(int i = 100; i < 200; ++i)

for i(200, 400, 2)
-- Not possible using foreach
for(int i = 200; i < 400; i += 2)



More information about the Digitalmars-d mailing list