15 lines
254 B
Python
15 lines
254 B
Python
# gen.send.preparation.stop.py
|
|
stop = False
|
|
|
|
def counter(start=0):
|
|
n = start
|
|
while not stop:
|
|
yield n
|
|
n += 1
|
|
|
|
c = counter()
|
|
print(next(c)) # prints: 0
|
|
print(next(c)) # prints: 1
|
|
stop = True
|
|
print(next(c)) # raises StopIteration
|