PHP basic learning: Process control implementation analysis. PHP has three major process controls: sequential control, branch control, and cyclic control. 1. sequential control: it refers to the execution of programs in sequence from above to the next step. 2. branch control: PHP has three major process control options: sequential control, branch control, and cyclic control.
1. sequential control: it refers to the execution of programs in sequence from above to the next step.
2. branch control: the program can be executed selectively. It can also be divided into single branch, multiple branch, and multiple branch.
A. single branch: Basic syntax structure:
If (conditional expression ){
Statement;
//.....;
} Tip:The conditional expression is true or false no matter how complex it is;
Eg:
A = 11;
If (a> 10 ){
Echo "a> 10 ";
}
B. multi-branch: Basic syntax:
If (conditional expression ){
Statement;
//.....;
} Else {
Statement;
//.....;
}
C. multiple branches: Basic syntax:
If (conditional expression ){
Statement; n statements;
} Else if (conditional expression ){
Statement; n statements;
} Elseif (conditional expression ){
Statement; n statements;
} Eles {
Statement; n statements;
} Tip:1. else if can have one or more. 2. the last else can have no
D. switch branch statement
Switch (expression ){
Case constant 1:
Statement; n statements;
Break;
Case constant 2:
Statement; n statements;
Break;
Case constant 3:
Statement; n statements;
Break;
Default:
Statement; n statements;
Break;
} Note:
1. one or more case statements 2. defaul statements are optional (based on the business logic of your code) 3. generally, after a case statement, a break is required to exit the switch statement. 4. constant type (int, float, string, Boolean)
Important:The program is first configured in the order of case. if none of them match, the program executes the content of the default statement until it encounters a break and then exits the switch;
If and switch branch comparison:
If is used to determine a certain range, and switch is used to determine a point, we can select them as follows:
Application scenario: when the branches are just a few points (for example, to determine the direction of the tank), swtich should be used. if your branches are in several regionsIf
Http://www.bkjia.com/PHPjc/326903.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/326903.htmlTechArticlePHP has three major process control: sequential control, branch control, cycle control. 1. sequential control: it refers to the execution of programs in sequence from above to the next step. 2. branch control: Select a program...