Syntax $iterable = function () { yield 1; yield 2; // ... }; use Symfony\Component\Console\Helper\ProgressBar; $progressBar = new ProgressBar($output); foreach ($progressBar->iterate($iterable) as $value) { // ... do some work } Non countable variable foreach ($progressBar->iterate($iterable, 100) as $value) { // ... do some work }