Google News
logo
PHP Program to continue statement in a loop
The `continue` statement is used in PHP loops to skip the current iteration of the loop and move on to the next iteration.

When a `continue` statement is encountered inside a loop, the remaining code in the current iteration is skipped, and the loop proceeds with the next iteration.

Here's an example of a `while` loop that uses a `continue` statement to skip odd numbers :
Program :
<?php
    // This is a PHP program that uses a while loop with a continue statement
    
    $i = 0;
    
    while ($i < 10) {
        $i++;
        if ($i % 2 == 1) {
            continue;
        }
        echo $i . " ";
    }
?>
Output :
2 4 6 8 10 
In this code, the `while` loop initializes the variable `$i` to `0`. Inside the loop, `$i` is incremented by `1` on each iteration. The `if` statement inside the loop checks if `$i` is odd, using the modulo operator (`%`). If `$i` is odd, then the `continue` statement is executed, and the remaining code in the current iteration is skipped.

When `$i` is even, the remaining code in the current iteration is executed, which in this case simply prints the value of `$i`, followed by a space.

This demonstrates how the `continue` statement can be used to skip certain iterations of a loop, based on a condition that is evaluated inside the loop.