What is the difference between break and continue in PHP?
break
will stop the current loop (or pass an integer to tell it how many loops to break from).
continue
will stop the current iteration and start the next one.
break
will exit the loop, while continue
will start the next cycle of the loop immediately.
break exits the loop you are in, continue starts with the next cycle of the loop immediatly.
Example:
$i = 10;
while (--$i)
{
if ($i == 8)
{
continue;
}
if ($i == 5)
{
break;
}
echo $i . "\n";
}
will output:
9
7
6
For the Record:
Note that in PHP the switch statement is considered a looping structure for the purposes of continue.