Saturday, August 26, 2017

PHP Continue Statement


The PHP continue statement is used to continue loop. It continues the current flow of the program and skips the remaining code at specified condition.

Syntax :
PHP Statement Here
Continue ;

Example :1 
<?php
for ($i = 0; $i < 5; ++$i) {
    if ($i == 2)
        continue;
    echo $i."<br/>";
}
?>

Above example you can clearly observe, It has skipped the loop 2 and move to next iteration of loop.
Output:
---------------------------
0
1
3
4

Example : 2
<?php
 $testers = array(1, 3, 4, 5);
    foreach($testers as $test){
        echo "Started here<br>";
        if ($test == 1):
        continue;
        endif;
        echo $test."<br>";
    }
?>

Output:
---------------------
Started here
Started here
3
Started here
4
Started here
5




No comments:

Post a Comment