PHP flow control continue statement

不言
Release: 2023-03-25 11:02:01
Original
2374 people have browsed it

This article mainly introduces the continue statement about PHP process control. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

This article is for basic useLearners, experts please close this page

It takes 15 minutes to read this article. It is hard to explain if it is difficult to understand. I encourage you to try it yourself

(PHP 4, PHP 5, PHP 7)

continue is used in the loop structure to skip the remaining code in this loop and start executing the next loop when the condition evaluates to true.

Note: Note that in PHP the switch statement is considered a loop structure that can use continue.

continue accepts an optional numeric parameter to determine how many loops to skip to the end of the loop. The default value is 1, which jumps to the end of the current loop.

<?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";
}
?>
Copy after login

Omitting the semicolon after continue can cause confusion. The following example shows how not to do this.

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

The desired result is:

0
1
3
4
Copy after login

But the actual output is:

2
Copy after login

Related recommendations:

php flow control break statement

php flow control what is foreach

The above is the detailed content of PHP flow control continue statement. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template