News for hackers. Stuff that matters.
Re:The scope of index variables in Python's for loops by cnvogel on Sunday January 18, 2015 @03:11PM (#8908667)
Probably this stems from the typical C-way of error-reporting out of a for-loop, which is to terminate earlier than the "regular loop condition", and hence a second test for the loop-condition can easily be used to check for abnormal termination...

    int i;
    for (i=0; i<length; i++) {
        if (is_broken(element[i]))
            break;
        process(element[i]);
    }
    /* if everything went fine, i == length, else we broke out early */
    if (i < length) {
        fprintf(stderr,"Something was broken.");
        return -1;
    }
Whereas the Python version obviously doesn't make sense in a pythonesque program iterating over sets of elements.

    for i in [1,2,3] :
        do_something(i)
    # ..now i is 3, not 4... obviously

There are no comments on this comment yet.