PHP Process Control Continue statement

Source: Internet
Author: User
Tags cdata
This article mainly introduces the PHP process control of the continue statement, has a certain reference value, now share to everyone, the need for friends can refer to

This paper tries to use the basic Learning Master, please close this page

This article read 15 minutes, understand difficult to say, encourage yourself to experiment

(PHP 4, PHP 5, PHP 7)

Continue is used in the loop structure to skip the remaining code in this loop and start the next loop when the condition evaluates to True.

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

Continue accepts an optional numeric parameter to decide to skip a few loops to the end of the loop. The default value is 1, which jumps to the end of the current loop.

<?phpwhile (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 causes confusion. The following examples indicate that this should not be done.

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

The desired result is:

0134

The actual output can be:

2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.