PHP Continue


 

PHP Continue

In this tutorial we will study about continue statement, continue statement is just reverse of the break statement.Examples in this tutorial will make it more clear.

In this tutorial we will study about continue statement, continue statement is just reverse of the break statement.Examples in this tutorial will make it more clear.

Continue Control Structure:

Continue is another type of control structure which is used to re-initialize the iteration without finishing the current iteration, continue is used within looping structures (like for, foreach, while, do-while and switch case)to avoid rest of the code. 

If we want to continue the higher levels of enclosing loops then we need to use continue with optional numeric argument.

Example:

<?php

$arr=array(1,2,3,4,5);

foreach($arr as $val):

if($val==4)continue;

echo $val."<br/>";

endforeach;

?>

Output:

1
2
3
5

Example:

<?php

$arr=array(1,2,3,4,5,56,76);

for($key=0;$key<7;$key++){

if(!($key%2))

continue;

else

echo $arr[$key]."<br/>";

}

Output:
2
4
56

Ads