Python - Try, Except, Finally, Continue, Break - Control flow explained
Python provides us with nice tools for controlling the flow of (not only) loops and handling exceptions.
Using those 5 keywords we can make sure that the flow of our program will go exactly as we would like.
try - Add before statement that may result in exception.
It is commonly used to manage runtime errors, ensuring the program can continue running.
except - Catch exception after try, be sure to add specific error that you want to catch. eq. TypeError
continue - Immediately go to the next loop iteration, skipping any remaining code in the current iteration.
(pass is simply doing nothing, they are NOT the same)
break - Immediately break out of the loop
finally - Executes at the end of each try block, whether or not an exception was raised.
It always runs after the try and except blocks, ensuring any necessary cleanup code is executed.
Note that it will still execute if break or continue was called within the try/except block.