for row in b:
for drug in drug_input:
for brand in brand_names[drug]:
from the third loop how do i exit the current loop and go to the next value of for row in b:
?
for row in b:
for drug in drug_input:
for brand in brand_names[drug]:
from the third loop how do i exit the current loop and go to the next value of for row in b:
?
Python supports
for...else
statements.else
block is evaluated if the innerbreak
is not fired.Exception handling beats setting variables all over the place IMO
This one uses a boolean to see if you are done yet:
This one will
continue
if no break was used. Theelse
will be skipped over if there was a break, so it will see the nextbreak
. This approach has the benefit of not having to use a variable, but may be harder to read to some.If you have too many embedded loops, it might be time for a refactor. In this case, I believe the best refactor is to move your loops into a function and use a
return
statement. That will force-exit out of any number of loops. For example:Now, perhaps reformulating your logic like this is tricky, but I bet the refactoring will help in other ways.
Latest PEP I see requesting this feature is 3136 (and was rejected): http://mail.python.org/pipermail/python-3000/2007-July/008663.html
Closest & cleanest thing I could see to what you want to do would be do the following (and since even type names are scoped, you could declare LocalBreak within the function its needed):