A generator behaves like a small state machine: calls to its iterator’s next() method advance execution, while yield pauses it until the next request. section 6.2.4
A generator moves through four states:
- Suspended start: created, but its code has not run. section 6.2.4
- Executing: runs from the beginning or resumes where it paused. section 6.2.4
- Suspended yield: produces a value and waits for another request. section 6.2.4
- Completed: reaches return or runs out of code. section 6.2.4
A two-step generator
NinjaGenerator("skulk") first yields “Hattori skulk”; its next request reaches return and completes the generator with “Yoshi skulk.” section 6.2.4








