View Full Version : Next operator

05-04-2004, 11:48 PM
perl has a next operator, such that while working in a foreach, while loop, you can skip to the next iteration if a condition is met.

i see PHP has a next function, but i am not sure if i should use it the same, or not.

those of you familiar with Perl, could you help me?

05-05-2004, 04:13 AM
from: http://php3.de/manual/en/control-structures.continue.php

continue is used within looping structures to skip the rest of the current loop iteration and continue execution at 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.

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

$i = 0;
while ($i++ < 5) {
echo "Outer<br />\n";
while (1) {
echo "&nbsp;&nbsp;Middle<br />\n";
while (1) {
echo "&nbsp;&nbsp;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