Lazy Line · Level 7 of 8

An endless machine

A generator that counts forever, and a loop that stops after three.

<?phpfunction naturals() {    $n = 1;    while (true) {        yield $n++;    }}foreach (naturals() as $n) {    if ($n > 3) {        break;    }    echo $n . PHP_EOL;}echo 'stopped' . PHP_EOL;

1. Predict the output

Tap the lines in the order you think they print.

  1. 1…
  2. 2…
  3. 3…
  4. 4…