sky_1 sky_1 -4 years ago 160
Python Question

python keyword continue is shifting control to finally keyword

I am actually new to python. While learning it I came across this piece of code.

Python official document says when encounter with continue statement,
control will shift to the beginning of the loop, but in this case it is shifting to final statement and executing from there onward. Is this a bug in python or what? Can somebody please explain this to me? Thanks.

def askint():

while True:

val =int(input("pleas enter an integer "))
print ("it seems like you did'n enter an integer ")
print ("yep that's an integer thank you")

print ('control is now on finally me')
print ('i am also getting executed ')


Answer Source

The finally code is always executed in a try/except block.

The continue doesn't skip it (or it would be a bug in python).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download