Lazy Line · Level 2 of 8

Take turns

The generator and the foreach loop both log. Watch them take turns.

<?phpfunction make() {    foreach (['tea', 'soup'] as $item) {        echo "make $item" . PHP_EOL;        yield $item;    }    echo 'machine empty' . PHP_EOL;}foreach (make() as $item) {    echo "use $item" . PHP_EOL;}echo 'done' . PHP_EOL;

1. Predict the output

Tap the lines in the order you think they print.

  1. 1…
  2. 2…
  3. 3…
  4. 4…
  5. 5…
  6. 6…