Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

Continue

Continue in For Loops

The continue statement halts the current iteration in the for loop and moves on to the next one.

Example

Skip to the next iteration if $x is 4:

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

Continue in While Loop

The continue statement halts the current iteration in the while loop and proceeds to the next one.

Continue Example

Skip to the next iteration if $x equals 4:

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

Continue in Do While Loop

The continue statement halts the current iteration in the do…while loop and moves on to the next one.

Example

Skip to the next iteration if $i is 3:

$i = 0;
do {
 $i++;
 if ($i == 3) continue;
 echo $i;
} while ($i < 6);

Continue in For Each Loop

The continue statement halts the current iteration in the foreach loop and proceeds to the next one.

Example

Skip 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>";
}