More powerful foreach statements

Kirk McDonald kirklin.mcdonald at gmail.com
Fri Jul 21 08:57:01 PDT 2006


Oskar Linde wrote:
> Python style ranges:
> 
> foreach(x; range(5))
>     ... x is 0,1,2,3,4
> foreach(x; range(1, 6))
>     ... x is 1,2,3,4,5
> foreach(x; range(1.5, 0, -0.25)) // bad idea to support doubles?
>     ... x is 1.5, 1.25, 1.0, 0.75, 0.5, 0.25
> 

For what it's worth, writing a Python 'xrange'-style construct in D 
isn't that hard. I've posted one previously to the group:

http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/38808

Some follow-ups to that post had templated versions.

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://dsource.org/projects/pyd/wiki



More information about the Digitalmars-d mailing list