Python for loop

In Python, the for loop works differently.If we try to modify the loop iterator variable, it will be simply skipped and iterator will continue from its next value irrespective of the modification.

So in case if we need to modify the loop iterator value in our logic, we have to choose while loop. for loop cannot be used in this scenario. Here is the code snippet to see it in action:

for i in range(1,10):
if i==3:
i+=2
print i

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.