Some quick questions

Jarrett Billingsley kb3ctd2 at yahoo.com
Wed Aug 8 04:50:56 PDT 2007


"Regan Heath" <regan at netmail.co.nz> wrote in message 
news:f9btus$2oqv$1 at digitalmars.com...
>
> I'd use a for loop.  That said it would be nice if there was a nicer way 
> to do this with foreach as it's the only 'container agnostic' way of 
> iterating, right?
>

Of course, depending on the container, changing the index may or may not 
make any sense.  Arrays are linear, maps are not.  So if you have a foreach 
loop that could skip elements, it would only be useful on those containers 
where skipping ahead made sense (you lose one element of that agnosticity 
(if that's even a word (which I doubt it is :X ))).

I'd say when you start needing to change the index, use a for loop; that's 
what it's there for. 




More information about the Digitalmars-d-learn mailing list