Hacker News new | past | comments | ask | show | jobs | submit login

I do something like this in "modern" Java to get for-each with index:

    { int i = -1; for (V v : list) { i++;
        // stuff
    } }
While declaring i = -1 to start is a little gross, I like that it has some of the same properties as a normal for loop. No effect on parent scope, and all loop-logic is concentrated on the first (textual) line.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: