PHP

Break & Continue Statement

PHP / Break & Continue Statement

Break & Continue Statement

Break Statement

The break statement is used to stop the execution of a loop or switch statement immediately. When break is used, the program exits the current loop or switch block.

  • Loops (for, while, do...while, foreach)
  • switch statement

Example

for ($i = 1; $i <= 5; $i++) {
   if ($i == 3) {
       break;
   }
   echo $i . " ";
}

?>

Continue Statement

The continue statement is used inside loops to skip the current iteration and move to the next iteration of the loop.

The continue statement is used 

  • for loop
  • while loop
  • do...while loop
  • foreach loop

Example

for ($i = 1; $i <= 5; $i++) {
   if ($i == 3) {
       continue;
   }
   echo $i . " ";
}

?>

Technology
PHP
want to connect with us ?
Contact Us