Joins
Nested Loops Join
Idea 2: Coroutines
A coroutine can output a value, and then resume control.
E.g. Generators in Python.
def gen(n):
for i in range(n):
print('before %s' % i)
yield i
print('after %s' % i)
i = gen(3) # Returns a value of type "generator"
try:
while True:
x = i.next()
print(' RECEIVED %s' % x)
except StopIteration:
pass
print('DONE')
Try the code: python gen.py
Unfortunately, C/C++ doesn't provide coroutines.
|