Difference between break and continue in php learning

Source: Internet
Author: User
This article introduces another important knowledge point in php learning. In flow control statements, we often use break and continue to transfer control statements. So what are the differences between the two?

This article introduces another important knowledge point in php learning. In flow control statements, we often use break and continue to transfer control statements. So what are the differences between the two.
1. First, we will introduce break. The break statement ends the execution of the current condition control statement, such as if, switch, or loop control statement, such as while, for, and foreach. The break statement can accept an optional parameter to determine the number of repeated loops.
The following is an example of a switch:
Switch ($ ){
Case "1 ":
Echo "the passed value is 1 ";
Break;
Case "2 ":
Echo "the passed value is 2 ";
Break;
}
2. the continue statement jumps out of the statement with the specified condition in this loop and continues to execute other loop statements. Break is used to terminate the statement execution under a specified condition, while the continue statement is used to exit the execution of a loop under a specified condition. Other loop statements continue to be executed.
For example:
For ($ I = 0; $ I <5; $ I ++ ){
If ($ I = 3 ){
Continue;
}
Echo $ I;
}
When $ I = 3, 3 is not output. jump out of this loop and execute the next loop.
Understanding the differences between the two is important for php learners. In development, we often need to determine how to jump out of control statements based on the conditions. to jump out, we need to master these two statements.

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.