PHP Continue

0
4KB

The continue statement can be used to jump out of the current iteration of a loop, and continue with the next.


Continue in For Loops

The continue statement stops the current iteration in the for loop and continue with the next.

ExampleGet your own PHP Server

Move to next iteration if $x = 4:

for ($x = 0; $x < 10; $x++) {
  if ($x == 4) {
    continue;
  }
  echo "The number is: $x <br>";
}
Try it Yourself »

Continue in While Loop

The continue statement stops the current iteration in the while loop and continue with the next.

Continue Example

Move to next iteration if $x = 4:

$x = 0;

while($x < 10) {
  if ($x == 4) {
    continue;
  }
  echo "The number is: $x <br>";
  $x++;
}
Try it Yourself »


Continue in Do While Loop

The continue statement stops the current iteration in the do...while loop and continue with the next.

Example

Stop, and jump to the next iteration if $i is 3:

$i = 0;

do {
  $i++;
  if ($i == 3) continue;
  echo $i;
} while ($i < 6);
Try it Yourself »

Continue in For Each Loop

The continue statement stops the current iteration in the foreach loop and continue with the next.

Example

Stop, and jump to the next iteration if $x is "blue":

$colors = array("red", "green", "blue", "yellow");

foreach ($colors as $x) {
  if ($x == "blue") continue;
  echo "$x <br>";
}
Try it Yourself »
Rechercher
Catégories
Lire la suite
Autre
PHP Functions
The real power of PHP comes from its functions. PHP has more than 1000 built-in functions, and...
Par PHP Tutorial 2024-05-17 07:53:06 0 4KB
Autre
PHP - Concatenate Strings
String Concatenation To concatenate, or combine, two strings you can use...
Par PHP Tutorial 2024-05-17 07:30:24 0 8KB
Autre
PHP Sorting Arrays
The elements in an array can be sorted in alphabetical or numerical order, descending or...
Par PHP Tutorial 2024-05-17 08:06:46 0 8KB
Autre
PHP while Loop
The while loop - Loops through a block of code as long as the specified condition is...
Par PHP Tutorial 2024-05-17 07:48:58 0 4KB
Autre
PHP - Escape Characters
Escape Character To insert characters that are illegal in a string, use an escape character. An...
Par PHP Tutorial 2024-05-17 07:32:36 0 11KB
Sociallez https://sociallez.com