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

Comments

Leave a Reply

Discover more from Chai's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading