PHP Continue

0
2K

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 »
Search
Categories
Read More
Other
PHP Global Variables - Superglobals
Superglobals were introduced in PHP 4.1.0, and are built-in variables that are always available...
By PHP Tutorial 2024-05-17 08:08:10 0 4K
Other
PHP foreach Loop
The foreach loop - Loops through a block of code for each element in an array or each...
By PHP Tutorial 2024-05-17 07:50:19 0 2K
Other
PHP Constants
Constants are like variables, except that once they are defined they cannot be changed or...
By PHP Tutorial 2024-05-17 07:39:53 0 2K
Other
PHP Data Types
PHP Data Types Variables can store data of different types, and different data types can do...
By PHP Tutorial 2024-05-17 07:27:24 0 2K
Other
PHP - $_SERVER
$_SERVER $_SERVER is a PHP super global variable which holds information about headers,...
By PHP Tutorial 2024-05-17 08:08:50 0 4K