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.