I am Python amateur and was trying to write a code to generate a Fibonacci Series when I came across a weird behaviour.
>>> def F(num): #line1
a,b = 1,2 #line2
yield a #line3
yield b #line4
while num>2: #line5
a,b = b,a+b #line6
yield b #line7
>>> gen = F(10) #line8
>>> #line9
The while
loop in the code is an infinite loop. My question is if the loop does not end then how did #line8
complete execution?
Thanks!!