Does python yield imply continue?

Viewed 15470

I have a for loop that checks a series of conditions. On each iteration, it should yield output for only one of the conditions. The final yield is a default, in case none of the conditions are true. Do I have to put a continue after each block of yields?

def function():
    for ii in aa:
       if condition1(ii):
           yield something1
           yield something2
           yield something3
           continue

       if condition2(ii):
           yield something4
           continue

       #default
       yield something5
       continue
6 Answers

This way is more clear, hope it helps, also thanks Anurag Uniyal.

def f():
    for i in range(3):
        yield i
        print(i+10)

list(f())

----------- after run ------------

10
11
12
[0, 1, 2]
Related