PHP Syntax Statements Jumping continue

 

- Info:

- continue statement is used inside looping statements to stop current iteration and continue with the next one.

- This means that you can use it to stop execution of for, foreach, while or do...while blocks.

 

- Syntax:

continue;

 

- Example:

- Create PHP Console Application Test.php.

 

Test.php

<?php

#CONTINUE. Output is: 124 since display of number 3 is skipped

for($i=1;$i<=4;$i++){

if($i==3) { continue; }

print($i);

}

#CONTINUE: 5

$array = array("John"=>1, "Jill"=>5);

foreach ($array as $value) {

if($value==1) continue;

print($value);

}

#CONTINUE. Output:1245 since display of number 3 is skipped.

$i = 0;

while($i<=4){

$i++;

if($i==3) { continue; }

print($i);

}

#CONTINUE. Output:1245 since display of number 3 is skipped.

$i = 0;

do{

$i++;

if($i==3) { continue; }

print $i;

} while($i<=4);

?>