python decrement at special case in for-loop

Viewed 157

I need to decrement in a python for-loop at a special case (or just don't increment).

In C-like languages, this can be easily accomplished by decrementing the index, or if you have an iterator-like structure you could just "decrement" the iterator. But I have no clue how to achieve this in python.

One solution would be to create a while loop and increment manually, but that would, in my case, bring in lots of extra cases, where just one case is needed when I could decrement.

C Example
for (int i = 0; i < N; ++i) {
    if (some_condition) {
        i--;
    }
}
Python equivalent
for i in range(0, N):
    if some_condition:
        i -= 1        # need something like this
        i = i.prev()  # or like this
0 Answers
Related