0
Loops In a Row
I noticed that when I use for loop on top of each other, the bottom one has no effect. What is the reason of this? https://code.sololearn.com/c9D75rQM2zPk/?ref=app
5 ответов
+ 2
You are using generator's yield function, which is don't save values after function calling over until it called again.. So there in loop, the value for c in none in last loop.
Check this
def count():
for i in range (1,6):
yield(i)
c=count()
print(*c) #output 1,2,3,4 5
print(*c) #output nothing..
So 2 loop not runs.
In your code that why only one loop running..
+ 5
the function you are using is a generator function. this will be stored in varibale c. Then you iterate over c. This can only be done ones, because then the generator is exhausted after iteration is fished. if you need to iterate twice, you should rethink your code / algorithm, or you have to run the generator function again.
The reason of this is, that the generator does not create all the values when the function is called and then return them. using yield gives only one value back at a given iteration cycle.
+ 2
Can you show the code?
0
Jayakrishna🇮🇳 i inserted
0
Jayakrishna🇮🇳 thanks i understand