Skip to content

PHP Continue Statement

Syntax

The continue statement in PHP is used inside loops to immediately jump to the next iteration, skipping any code below it in the current iteration.

// Using continue in a loop
foreach ($array as $value) {
if (condition) {
continue; // Skip to the next iteration
}
// Code to execute if condition is not met
}

Example

// Loop through numbers and skip even numbers
for ($i = 1; $i <= 5; $i++) {
if ($i == 3) {
continue; // Skip even numbers
}
echo $i . "\n";
}
/* Output:
1
2
4
5
*/