for loop
generates disposable variable if you use it like above. For example, a list object
is used again and again in a loop but a disposable iterator is deleted automatically after use.
And yield
is a term like return
which is used in functions. It gives a result and use it again in loop.
Your codes give you the number known as fibonacci.
def fib():
a, b = 0,1 #initially a=0 and b=1
while True: #infinite loop term.
yield b #generate b and use it again.
a,b = b, a + b #a and b are now own their new values.
for i in fib(): #generate i using fib() function. i equals to b also thanks to yield term.
print(i) #i think you known this
if i>100:
break #we have to stop loop because of yield.