Break and Continue in While Loop

You can also use break and continue in while loops:

Break Example
<?php
$x = 0;

while($x < 10) {
if ($x == 4) {
break;
}
echo “The number is: $x <br>”;
$x++;
}
?>

Continue Example
<?php
$x = 0;

while($x < 10) {
  if ($x == 4) {
    $x++;
    continue;
  }
  echo "The number is: $x <br>";
  $x++;
}
?>
Scroll to Top