Introduction
In the previous post we looked the finally keyword. We discussed how it could be used to write a code block which is executed whether or not the code within the try-block threw an exception.
In this post we’ll look at another Python keyword which helps you jump over an iteration in case you don’t want to handle the current value in the loop in any way.
There are cases where you simply don’t want to handle certain values while iterating over a collection. The for-each block will be executed for each element in the collection but for some of them this logic should not be executed.
You can easily solve this with if-else block(s), but there’s another solution.
Continue
The continue keyword will stop the execution of the for-each block. Execution will jump back to the beginning of the loop and take the next value in the collection. This keyword exists in other popular languages such as Java or C# and it works in exactly the same way in Python.
Read more of this post