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

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s