downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  

<breakswitch>
Last updated: Thu, 26 Jun 2008

continue

continue is used within looping structures to skip the rest of the current loop iteration and continue execution at the condition evaluation and then the beginning of the next iteration.

Note: Note that in PHP the switch statement is considered a looping structure for the purposes of continue.

continue accepts an optional numeric argument which tells it how many levels of enclosing loops it should skip to the end of.

<?php
while (list($key, $value) = each($arr)) {
   if (!(
$key % 2)) { // skip odd members
      
continue;
   }
  
do_something_odd($value);
}

$i = 0;
while (
$i++ < 5) {
   echo
"Outer<br />\n";
   while (
1) {
       echo
"  Middle<br />\n";
       while (
1) {
           echo
"  Inner<br />\n";
           continue
3;
       }
       echo
"This never gets output.<br />\n";
   }
   echo
"Neither does this.<br />\n";
}
?>

Omitting the semicolon after continue can lead to confusion. Here's an example of what you shouldn't do.

<?php
 
for ($i = 0; $i < 5; ++$i) {
     if (
$i == 2)
         continue
     print
"$i\n";
  }
?>

One can expect the result to be :

0
1
3
4

but this script will output :

2

because the return value of the print() call is int(1), and it will look like the optional numeric argument mentioned above.



add a noteadd a note User Contributed Notes
continue
There are no user contributed notes for this page.




<breakswitch>
Last updated: Thu, 26 Jun 2008
show source | credits | sitemap | contact | advertising | mirror sites
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://phpbuilder.com/
Last updated: Tue Nov 1 20:20:59 2005 EST
Columns / Articles | Tips / Quickies | News | News Linking and RSS Feeds | Shared Code Library
Mail Archives | Support / Discussion Forums | Get Started! Links | Contribute! | Docs