Skip to content
No description, website, or topics provided.
PHP
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
README.md
composer.json
phpunit.xml.dist

README.md

control-structures.php

Loop::while()

<?php

use zonuexe\Loop;

$i = 0;

Loop::while(
    function () use (&$i) { return $i < 10; },
    function () use (&$i) { var_dump($i++); }
);

Loop::do_while()

<?php

use zonuexe\Loop;

$i = 0;

Loop::do_while(
    function () use (&$i) { var_dump($i++); },  // dumps "int(0)"
    function () use (&$i) { return $i < 0; }
);

Loop::until()

<?php

use zonuexe\Loop;

$i = 0;

Loop::until(
    function () use (&$i) { return $i === 10; },
    function () use (&$i) { var_dump($i++); }
);

Loop::do()

<?php

use zonuexe\Loop;

$i = 0;

Loop::do(
    function () use (&$i) { var_dump($i++); },
    ['while' => function () use (&$i) { return $i < 0; }]
);
<?php

use zonuexe\Loop;

$i = 0;

Loop::do(
    function () use (&$i) { var_dump($i++); },
    ['until' => function () use (&$i) { return $i === 10; }]
);

Loop::for()

<?php

use zonuexe\Loop;

$i = 0;

Loop::for(
    function () use (&$i) { $i = 0; },
    function () use (&$i) { return $i < 10; },
    function () use (&$i) { $i++; },
    function () use (&$i) { var_dump($i); }
);

Loop::foreach()

<?php

use zonuexe\Loop;

Loop::foreach(range(1, 10), fn($k, $v) => print $v . PHP_EOL);
You can’t perform that action at this time.