PHP continue Statement (original) (raw)
Last Updated : 25 Aug, 2022
The continue statement is used within a loop structure to skip the loop iteration and continue execution at the beginning of condition execution. It is mainly used to skip the current iteration and check for the next condition.
The continue accepts an optional numeric value that tells how many loops you want to skip. Its default value is 1.
Syntax:
loop { // Statements ... continue; }
Example 1: The following code shows a simple code with a continue statement.
PHP
<?php
`` for
(
$num
= 1;
$num
< 10;
$num
++)
`` {
`` if
(
$num
% 2 == 0)
`` {
`` continue
;
`` }
`` echo
$num
.
" "
;
`` }
?>
Example 2: The following code shows a continue 2 statement that will continue with the next iteration of the outer loop.
PHP
<?php
`` $num
= 4;
`` while
(
$num
++ < 5)
`` {
`` echo
"First Loop \n"
;
`` while
(1)
`` {
`` echo
"Second Loop \n"
;
`` continue
2;
`` }
`` echo
"Outer value \n"
;
`` }
?>
Output
First Loop Second Loop
Reference: https://www.php.net/manual/en/control-structures.continue.php
Similar Reads
- PHP Tutorial PHP is a widely used, open-source server-side scripting language primarily designed for web development. It is embedded directly into HTML and generates dynamic content on web pages, making it essential for building data-driven websites. It allows developers to handle database interactions, session 10 min read
- PHP Introduction PHP stands for Hypertext Preprocessor. It is an open-source, widely used language for web development. Developers can create dynamic and interactive websites by embedding PHP code into HTML. PHP can handle data processing, session management, form handling, and database integration. The latest versi 9 min read