Python for loop

In Python, the for loop works differently.If we try to mod­i­fy the loop iter­a­tor vari­able, it will be sim­ply skipped and iter­a­tor will con­tin­ue from its next val­ue irre­spec­tive of the mod­i­fi­ca­tion.

So in case if we need to mod­i­fy the loop iter­a­tor val­ue in our log­ic, we have to choose while loop. for loop can­not be used in this sce­nario. Here is the code snip­pet to see it in action:

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



Leave a Reply

%d bloggers like this: