Content deleted Content added
→Python: Added relevent link |
No edit summary |
||
Line 40:
==Uses==
Generators are usually [[execution (computers)|invoked]] inside loops.<ref name=icon>The [[Icon (programming language)|Icon Programming Language]] utilizes generators to implement its goal directed through evaluation. In Icon, generators can be invoked in contexts outside of the normal looping control structures.</ref> The first time that a generator invocation is reached in a loop, an iterator [[object (computer science)|object]] is created that encapsulates the state of the generator routine at its beginning, with arguments bound to the corresponding [[parameter (computer science)|parameter]]s. The generator's body is then executed in the context of that iterator until a special ''yield'' action is encountered; at that time, the value provided with the ''yield'' action is used as the value of the invocation expression. The next time the same generator invocation is reached in a subsequent iteration, the execution of the generator's body is resumed after the ''yield'' action, until yet another ''yield'' action is encountered. In addition to the ''yield'' action, execution of the generator body can also be terminated by a ''finish'' action,
at which time the innermost loop enclosing the generator invocation is terminated.
|