for i in range(0,100): while True: try: # do stuff except SomeSpecificException: continue break
Here is what the above code is Doing:
1. It’s looping 100 times.
2. It’s trying to do stuff.
3. If it gets a SomeSpecificException, it will continue to the next iteration of the outer loop.
4. If it doesn’t get a SomeSpecificException, it will break out of the inner loop.
The continue statement is used to skip the rest of the code inside a loop for the current iteration only.
A continue statement rejects all the remaining statements in the current iteration of the loop and moves the control back to the top of the loop.
The continue statement can be used in both while and for loops.