Skip to content

Instantly share code, notes, and snippets.

@killpond
Created February 14, 2014 13:21
Show Gist options
  • Save killpond/9000853 to your computer and use it in GitHub Desktop.
Save killpond/9000853 to your computer and use it in GitHub Desktop.
Switch with continue may not do as expected when used in for()
<?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