Why does this work?
def nextSquare():
i = 1;
# An Infinite loop to generate squares
while True:
yield i*i
i += 1 # Next execution resumes
# from this point
# Driver code to test above generator
# function
for num in nextSquare():
if num > 100:
break
print(num)
But not this?
def nextSquare():
i = 1;
# An Infinite loop to generate squares
while True:
yield i*i
i += 1 # Next execution resumes
# from this point
# Driver code to test above generator
# function
for num in 1:
if num > 100:
break
print(num)
An integer is returned each time nextsquare is run so what is the difference between the first time nextsquare returns in
for num in nextSquare():
and
for num in 1: