Introduction
Yield lets a method pause and run a block of code given to it. This helps make methods more flexible and reusable.
When you want a method to run some custom code given by the user.
When you want to repeat a task but allow small changes each time.
When you want to separate the main work from small details.
When you want to write cleaner code without passing many parameters.
When you want to create your own iterator or callback.