def f1(n):
	for i in range(n,2*n):
		return i

def f2(n):
	for i in range(n,2*n):
		print(i)

def f3(n):
	for i in range(n,2*n):
		yield i

def f4():
	i=0
	while True:
		yield i
		i=i+7


# important example for the assignment
def f5(n):
	return f3(2*n)

print(f1(10))

f2(10)
for i in f3(10):
	print(i)

for i in f3(10):
	for j in f3(100):
		print("i="+str(i)+" j="+str(j))

for i in f5(5):
	print(i)


# yield statements produce generators, you can go through the
# results of a generator one item at a time as follows

print("pulling first 10 from 4,5,6,7 one member at a time")
z=f3(4) # get back a generator
count=0
while count<10:
	try:
		i=next(z)
	except StopIteration as e:
		# the generator is exhausted
		break
	print(str(i))
	count+=1

z=f4() # get back a generator
count=0

print("pulling first 10 from 0,7,14,21,28,... one member at a time")
while count<10:
	try:
		i=next(z)
	except StopIteration as e:
		# the generator is exhausted
		break
	print(str(i))
	count+=1
	

