How to skip iterations in a loop?
I have a loop going, but there is the possibility for exceptions to be raised inside the loop. This of course would stop my program all together. To prevent that I catch the exceptions and handle them. But then the rest of the iteration runs even though an exception occurred. Is there a keyword to use in my except:
clause to just skip the rest of the current iteration?
Solution 1:
You are looking for continue.
Solution 2:
for i in iterator:
try:
# Do something.
pass
except:
# Continue to next iteration.
continue