The PHP continue statement is used inside the different loops to take control of the current iteration to the beginning of the loop if a certain condition is met.
The continue statement can be used with all types of loops like while, do-while, for, foreach, etc. The continue statement allows the user to skip the statements inside the body of the current loop at the specified condition.
PHP Continue Statement Syntax
continue;
PHP Continue Example with for loop
Example
<?php for ($i =1; $i<=6; $i++) { if ($i == 4) { /* The continue statement is encountered when the value * of i=4. */ continue; } echo "$i </br>"; //echo statement will not print anything when i=4. } ?>
Output
1
2
3
5
6
2
3
5
6
PHP Continue Example with while loop
Example
<?php $i=0; while ($i<=10) { if ($i == 4) { /* The continue statement is encountered when the value * of i=4. */ $i++; continue; } echo "$i </br>"; //echo statement will not print anything when i=4. $i++; } ?>
Output
0
1
2
3
5
6
7
8
9
10
1
2
3
5
6
7
8
9
10
PHP Continue example with do while loop
Example
<?php $i=0; do { if ($i == 4) { /* The continue statement is encountered when the value * of i=4. */ $i++; continue; } echo "$i </br>"; //echo statement will not print anything when i=4. $i++; } while ($i<=10) ?>
Output
0
1
2
3
5
6
7
8
9
10
1
2
3
5
6
7
8
9
10