PHP continue & break


continue skips a step of a loop.

<?PHP
for ($i=0;$i<10;$i++)
{
   echo "$i, ";  //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
}
for ($i=0;$i<10;$i++)
{
   if ($i % 3 == 0) continue;
   echo "$i, ";  //1, 2, 4, 5, 7, 8, 
}
?>

break stops a loop if the condition is true.
<?PHP
for ($i=0;$i<10;$i++)
{
   if ($i == 4) break;
   echo "$i, ";  //0, 1, 2, 3, 4, 
}
?>

break n can be used to jump out of n loops.
<?PHP
for ($i=0;$i<10;$i++)
{
   for ($j=1;$j<4;$j++)
   {
	   if ($i == 4) break 2;
	   echo "$i, $j\n";
   }
}
//the result is:
	0, 1
	0, 2
	0, 3
	1, 1
	1, 2
	1, 3
	2, 1
	2, 2
	2, 3
	3, 1
	3, 2
	3, 3
?>