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:
?
If you have three levels of looping in one method then you probably need to rethink your design.
all
andany
to avoid writing explicit loops.Doing either of these should mean that you no longer have this issue.
I would consider putting the two inner loops in function and using return from there. Probably rethinking what you are doing and how gives the better alternative to that though.
Could you give your current pseudo code, input and output, so we could try to remove the need for the break in first place? We need to see where the loop variables are used or better still, what is the goal of the processing.
Python doesn't have a control structure for breaking from two loops at once, so you need to do something manual like this.
Untested:
try
/except
/raise
, as suggested in @gddc's comment, is one possibility. Another one is to "wrap up" the two nested loops into one:now, a
break
from thefor brand
nested loop will go back to thefor row
outer loop level. Of course, this works only when the code that is here replaced by...
does not need to see thedrug
name bound to the drug currently being examined. Is that the case for you?