The remark "in PHP the switch statement is considered a looping structure for the purposes of continue" near the top of this page threw me off, so I experimented a little using the following code to figure out what the exact semantics of continue inside a switch is:
<?php
for( $i = 0; $i < 3; ++ $i )
{
echo ' [', $i, '] ';
switch( $i )
{
case 0: echo 'zero'; break;
case 1: echo 'one' ; XXXX;
case 2: echo 'two' ; break;
}
echo ' <' , $i, '> ';
}
?>
For XXXX I filled in
- continue 1
- continue 2
- break 1
- break 2
and observed the different results. This made me come up with the following one-liner that describes the difference between break and continue:
continue resumes execution just before the closing curly bracket ( } ), and break resumes execution just after the closing curly bracket.
Corollary: since a switch is not (really) a looping structure, resuming execution just before a switch's closing curly bracket has the same effect as using a break statement. In the case of (for, while, do-while) loops, resuming execution just prior their closing curly brackets means that a new iteration is started --which is of course very unlike the behavior of a break statement.
In the one-liner above I ignored the existence of parameters to break/continue, but the one-liner is also valid when parameters are supplied.