PHP Continue

0
4K

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 »
Pesquisar
Categorias
Leia Mais
Outro
الثورة البلوكتشين وتحولاتها في الصناعات المختلفة
مقدمة: شهدت تقنية البلوكتشين ثورة هائلة في السنوات الأخيرة، حيث أصبحت لديها القدرة على تغيير...
Por MOHAMED ATTALLAH 2024-05-14 14:03:03 0 7K
Outro
PHP Comments
Comments in PHP A comment in PHP code is a line that is not executed as a part of the program....
Por PHP Tutorial 2024-05-17 07:14:49 0 6K
Outro
PHP Break
The break statement can be used to jump out of different kind of loops. Break in For...
Por PHP Tutorial 2024-05-17 07:50:37 0 5K
Outro
PHP Shorthand if Statements
Short Hand If To write shorter code, you can write if statements on one line....
Por PHP Tutorial 2024-05-17 07:47:03 0 4K
Outro
PHP Nested if Statement
Nested If You can have if statements inside if statements, this is...
Por PHP Tutorial 2024-05-17 07:47:26 0 4K
Sociallez https://sociallez.com