The
break
statement is used to jump out of loops
for ($x = 0;  $x < 10;  $x++) {
  if ($x == 7) {
    break;
  }
  echo "$x"."\n";
}
Another example using
break
statement In this example prints numbers less than 6
for ($x = 0;  $x < 10;  $x++) {
  if ($x*$x > 30) {
    break;
  }
  echo "$x"."\n";
}
Uses
break
statement instead of for loop condition section
for ($i = 0;  ;  $i ++) {
  if ($i == 10) {
    break;
  }
  echo $i . "\n";
}
by Valeri Tandilashvili
2 years ago
PHP
Loops
1
Pro tip: use ```triple backticks around text``` to write in code fences