
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP continue Statement
Introduction
The continue statement is one of the looping control keywords in PHP. When program flow comes across continue inside a loop, rest of the statements in current iteration of loop are skipped and next iteration of loop starts. It can appear inside while, do while, for as well as foreach loop.
Syntax
while (expr) { .. .. if (expr1) continue; .. .. }
In following example, continue statement will be executed every time while loop's counter variable $x is even numbered. As a result odd numbers between 1 to 10 will be printed
Example
<?php $x=1; while ($x<10){ $x++; if ($x%2==0) continue; echo "x = $x" . "
"; } ?>
Output
This will produce following result −
x = 3 x = 5 x = 7 x = 9
The keyword continue can have an optional numeric argument to specify how many levels of inne loops are to be skipped. Default is 1
In following example continue keyword is used with a level argument in inner loop
Example
<?php for ($i = 1;$i<=5;$i++) { echo "Start Of outer loop
"; for ($j=1;$j<=5;$j++) { if ($j >3) continue 2; echo "I : $i J : $j"."
"; } echo "End of inner loop
"; } ?>
Output
This will produce following result −
Start Of outer loop I : 1 J : 1 I : 1 J : 2 I : 1 J : 3 Start Of outer loop I : 2 J : 1 I : 2 J : 2 I : 2 J : 3 Start Of outer loop I : 3 J : 1 I : 3 J : 2 I : 3 J : 3 Start Of outer loop I : 4 J : 1 I : 4 J : 2 I : 4 J : 3 Start Of outer loop I : 5 J : 1 I : 5 J : 2 I : 5 J : 3
- Related Articles
- Java continue statement with Loop
- Continue Statement in C/C++
- The continue statement in JavaScript
- Continue statement in Dart Programming
- What is continue statement in JavaScript?
- Continue Statement in C/C++ Programming
- Why does Lua have no “continue” statement?
- How to use continue statement in Python loop?
- Can we use continue statement in a Python if clause?
- PHP break Statement
- PHP declare Statement
- PHP include Statement
- PHP include_once Statement
- PHP require Statement
- PHP require_once Statement

Advertisements