3v4l.org

run code in 300+ PHP versions simultaneously
<?php class FooNoMoreException extends Exception {} class Foo { protected $count = 500; public function step() { if (!$this->count) { throw new FooNoMoreException('No more steps to take.'); } $this->count--; $this->addStep(); } public function addStep() { $this->count++; } } // This one $f = new Foo; try { while ($f->step() || true) {} } catch (FooNoMoreException $e) {} var_dump($f); // Or this one $d = new Foo; while (1) { try { $d->step(); } catch (FooNoMoreException $e) { break; } } var_dump($d);

preferences:
37.08 ms | 402 KiB | 5 Q