PHP uses continue to skip the rest of the code in this cycle note

Source: Internet
Author: User
Tags parse error
The continue jump statement is used to skip statements that specify conditions in this loop, and to continue executing other loop statements. The following article mainly introduce to you in PHP with continue skip this cycle of the remainder of the code of a note, the content of the text in the basis of comparison, the need for friends can refer to the following to see together.

Objective

As we all know, continue in PHP is used to skip the remaining code in this loop and start the next loop when the condition evaluates to True. It must be noted that the use of continue to use ";" To separate other code, or it could cause an error!

Continue usage:

<?phpfor ($n = 0; $n < 5; $n + +) {if ($n = = 2)  continue;  echo "$n \ n";}? >

Output Result:

0 1 3 4

Obviously, when $n equals 2, the output is skipped, just in line with our wishes. If the semicolon is missing, you will get an error!

The wrong code:

<?phpfor ($n = 0; $n < 5; $n + +) {if ($n = = 2)  continue  echo "$n \ n";}? >

Error message:

Parse error:syntax error, unexpected ' echo ' (T_echo) in D:\phpStudy\WWW\demo\fun\continue.php on line 5

So note: We use the continue must be careful not to miss the semicolon!

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.