Created
February 14, 2014 13:21
-
-
Save killpond/9000853 to your computer and use it in GitHub Desktop.
Switch with continue may not do as expected when used in for()
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 | |
for ($i = 0; $i < 10; $i++) { | |
switch($i) { | |
case 4 : | |
case 5 : | |
echo 'HIT PRE CONTINUE'.PHP_EOL; | |
if ($i == 5) { | |
continue; // Expected this to skip the for loop, skips to the break instead. | |
} | |
echo 'HIT POST CONTINUE'.PHP_EOL; | |
break; | |
} | |
echo $i.PHP_EOL; | |
} | |
/* | |
-- OUTPUT -- | |
0 | |
1 | |
2 | |
3 | |
HIT PRE CONTINUE | |
HIT POST CONTINUE | |
4 | |
HIT PRE CONTINUE | |
5 | |
6 | |
7 | |
8 | |
9 | |
-- EXPECTED -- | |
0 | |
1 | |
2 | |
3 | |
HIT PRE CONTINUE | |
HIT POST CONTINUE | |
4 | |
HIT PRE CONTINUE | |
6 | |
7 | |
8 | |
9 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment