Going through a book on coding in D, http://ddili.org/ders/d.en/foreach.html , I find the following very useful feature:

When two names are specified in the names section [with a plain array], they represent an automatic counter and the value of the element, respectively:
    foreach (i, element; array) {
        writeln(i, ": ", element);
    }

I understand that foreach is built on top of a for loop... I'm just wondering why I can't access the automatic counter from a doubly linked list, or an associative array, or some range? It's pretty common for me to have to rewrite foreach loops to be for loops when I get to the bottom and realize I need to know where in the sequence I am...

Reply via email to