D Recurrences

Steven Schveighoffer schveiguy at yahoo.com
Thu Jun 9 11:08:49 PDT 2011


On Thu, 09 Jun 2011 14:02:47 -0400, Ben Grabham <Evil.Nebster at gmail.com>  
wrote:

> Also, when using a foreach, is there a special syntax that says include  
> the last number?
> As an example, if I want to loop from -n to +n, I have to do foreach(i;  
> -n..n+1)

No.  Almost all ranges in D are open interval on the right (don't include  
the right element).

There are some corner cases where this can be a problem, like if you  
wanted to iterate all the possible ubyte values, you have to do funky  
stuff like:

foreach(uint _tmp; ubyte.min..ubyte.max + 1) { auto ub = cast(ubyte)_tmp;  
... }

-Steve


More information about the Digitalmars-d mailing list