Analysis on the difference between break and continue in PHP _ PHP Tutorial

Source: Internet
Author: User
The difference between the break and continue process control commands in PHP is analyzed. The following example shows that break is used to jump out of the current execution cycle and stop executing the loop. Copy the code as follows :? Php $ i0; while ($ i7) {if ($ arr [$ I] stop) {break example below
Break is used to jump out of the current execution cycle and stop executing the loop.

The code is as follows:


$ I = 0;
While ($ I <7 ){
If ($ arr [$ I] = "stop "){
Break;
}
$ I ++;
}
?>


Continue immediately stops the current execution cycle, returns to the condition judgment of the loop, and continues the next loop.

The code is as follows:


While (list ($ key, $ value) = each ($ arr )){
If ($ key = "zhoz") {// if the queried object value is zhoz, this record will not be displayed.
Continue;
}
Do_something ($ value );
}
// Example 2
Foreach ($ list as $ temp ){
If ($ temp-> value = "zhoz "){
Continue; // if the queried object value is zhoz, this record will not be displayed.
}
Do_list; // records in the array are displayed here.
}
?>


Note: The goto loop command cannot be used in PHP.

Break is used to jump out of the current execution cycle and stop executing the loop. The code is as follows :? Php $ I = 0; while ($ I 7) {if ($ arr [$ I] = "stop") {break...

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.