Skip to main content

Break out of more than 2 loops in python

If you want to break out of a loop in Python, just use "break". How about when you need to bread out of more than 2 loops in Python?

Here is a hint: Using Raise and Exception.

try:
   ...
   if (condition): #You want to break your loop here
      raise GetOutOfLoop
except GetOutOfLoop:
   pass

Comments

  1. No more updates here?? Bring your work in the wide open, trigger the minds of the the laymen and everybody will understand the relevance of your fascinating job, the algorithmic analysis and the theorem of Pythagoras. All the best to you Thu!

    ReplyDelete

Post a Comment