Created
March 16, 2022 20:46
-
-
Save flavioheleno/033a23748aa8607fecb27642320ead31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function check(int &$val): Generator { | |
while ($val === 0) { | |
yield 1; | |
} | |
} | |
$var = 0; | |
$loop = 0; | |
foreach (check($var) as $dummy) { | |
// do something cool here | |
echo 'Loop: ', $loop, PHP_EOL; | |
// when should we leave? | |
if (++$loop > 10) { | |
$var = 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment