In Python, a loop does not increment i ; instead, it assigns values ββfrom an iterable object (in this case, a list) to it. Therefore, changing i inside the for loop does not "confuse" the loop, because in the next iteration i next value will simply be assigned.
In the code you indicated when i is 6, it then decreases in the loop, so that it changes to 5 and then prints. In the next iteration, Python simply sets it to the next value in the list [0,1,2,3,4,5,6,7,8,9] , which is 7, and so on. The loop ends when there are no more values.
Of course, the effect you get in the C loop that you provided can still be achieved in Python. Since each for loop is an illustrious while loop, in the sense that it can be transformed as follows:
for (init; condition; term) ...
It is equivalent to:
init while(condition) { ... term }
Then your infinite loop can be written in Python as:
i = 0 while i < 10: if i > 5: i -= 1 print i i += 1
spatz source share