
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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" . "\n"; } ?>
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\n"; for ($j=1;$j<=5;$j++) { if ($j >3) continue 2; echo "I : $i J : $j"."\n"; } echo "End of inner loop\n"; } ?>
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 Questions & Answers
- 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
- How to use continue statement in Python loop?
- Why does Lua have no “continue” statement?
- PHP declare Statement
- PHP include Statement
- PHP include_once Statement
- PHP require Statement
- PHP require_once Statement
- PHP return Statement
- PHP goto Statement
Advertisements