Continue Statement in PHP Statement in PHP : Tutorial


In PHP continue is used within for and while loops to skip the rest of the current loop iteration and continue execution at the condition evaluation and then the beginning of the next iteration.

Syntax :
continue;
Break ends a loop completely,where as continue skip the current iteration and moves on to the next iteration.

while ($number) { <---------------
     continue; --- goes back here -

     break; ----- jumps here ---
    }<----------------------------
Example :
<?php

for ($i = 1; $i <= 10; $i++) {
	if($i<=5) 
     echo $i."<br>";
    else
      continue;

?>
Output

1 2 3 4 5



Example : break and continue
<?php

$number = 1;
while ($number++)
{
    if ($number == 2)
    {
        continue;
    }
    if ($number == 6)
    {
        break;
    }
    echo $number . "<br>";
}

?>
Output

3 4 5