Foreach Range Statement

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Jul 22 20:22:23 PDT 2007


"Xinok" <xnknet at gmail.com> wrote in message 
news:f80qof$2n0l$1 at digitalmars.com...

> foreach(i; 0..100)

This is almost identical to the syntax in MiniD:

for(i: 0 .. 100)

It could be done with for or foreach; I just chose for because normally you 
use for loops to iterate over ranges of integers.

You can also come up with a pretty simple short-term solution that'll be 
fairly efficient (though not as efficient as if the compiler were aware of 
this kind of loop intrinsically) by making a struct 'range' which has a 
static opCall to construct a range and an opApply to iterate over the 
values, so that it'd look like:

foreach(i; range(100))

Which isn't terrible at all. 





More information about the Digitalmars-d mailing list