for($i = 0, $i < 3, $i++) {
switch($i) {
case 0:
case 2:
break;
case 1:
echo ', ';
continue;
}
echo $i;
}
예상 출력: 0, 2
실제 출력: 0, 12
음.. 그러니까.. continue가 break처럼 동작하는 이유가 무엇인가요?
의견 (0)
더 많은 의견 보기
for($i = 0, $i < 3, $i++) {
switch($i) {
case 0:
case 2:
break;
case 1:
echo ', ';
continue;
}
echo $i;
}
예상 출력: 0, 2
실제 출력: 0, 12
음.. 그러니까.. continue가 break처럼 동작하는 이유가 무엇인가요?
PHP는 이상하게도 switch를 루프 구조로 취급해요.
Note: In PHP the switch statement is considered a looping structure for the purposes of continue. continue behaves like break (when no arguments are passed). If a switch is inside a loop, continue 2 will continue with the next iteration of the outer loop. - PHP 기술문서 - continue
for($i = 0, $i < 3, $i++) {
switch($i) {
case 1:
continue 2;
}
echo $i;
}