PHP Basic Flow control statement continue and break usage

Source: Internet
Author: User
Continue
The Continue is used in the loop structure to skip the remaining code in this loop and start the next loop.

Note: Notice that the switch statement is considered a looping structure for continue purposes in the PHP tutorial.

Continue accepts an optional numeric parameter to decide to skip a few loops to the end of the loop.

<?php while (list ($key, $value) = each ($arr)) {     if ($key = = "Zhoz")    {     //If the value of the queried object is equal to Zhoz, the record is not displayed.     continue;     } Do_something ($value); }

Example 2

<?phpforeach ($list as $temp) {     if ($temp->value = = "Zhoz")    {     continue;     If the value of the query to an object equals Zhoz, the record is not displayed.     } do_list; This shows the records in the array}

Break
Break ends Current For,foreach,while,do: The execution of the while or switch structure.

Break can accept an optional numeric parameter to decide to jump out of a few loops.

<?php$arr = Array (' One ', ' one ', ' one ', ' three ', ' four ', ' Stop ', ' five ') and while (list (, $val) = each ($arr)) {   if ($val = = ' Stop ') {break       ;    /* You could also write ' break 1; */   }   echo "$val <br>n";} /* Using the optional argument. */$i = 0;while (+ + $i) {   switch ($i) {case   5:       echo ' at 5<br>n ';       Break 1;  /* Exit only the switch. *   /Case:       Echo ' at 10; Quitting<br>n ";       Break 2;  /* Exit the switch and the while. *   /default: Break       ;   }}? >

Example two

<?php $i = 0; while ($i < 7) {     if ($arr [$i] = = "Stop")     {break     ;     } $i + +;}?>

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.