<div dir="ltr">I am doing "Building Skills in Python". In the Generator Function example at [url]<a href="http://www.itmaybeahack.com/homepage/books/python/html/p02/p02c08_generators.html#generator-function-example[/url]">http://www.itmaybeahack.com/homepage/books/python/html/p02/p02c08_generators.html#generator-function-example[/url]</a> i can't understand, how it is working properly.<br>
what i understood is as follows:><br>1)First it makes count = 0<br>2)then it goes straight in for loop<br>3)Since the first color is red, it goes in else block and increment count to 1 and stop execution.<br>4)Now its next method is called using list comprehension, and it resumes its execution and yield its first value i.e. 1.Note that the yield statement is outside the for loop.<br>
5)Now there is no further yield statement which can stop execution of countreds() function.So it raises StopExecution exception<br><br>But this is not what is happening..... why?<br></div>