"PHP" Process Control

Source: Internet
Author: User

First, sequential structure

A) php script from top to bottom, from left to right execution order is the order structure!

Two, branch structure

A) Single branch structure

IF (conditional expression) {

program Body;

}

Execution process:

1. First determine if the conditional expression is true

2. If it is established, the program body in curly braces is executed

3. If not, jump directly out of the current branch

b) Bidirectional branching structure

IF (conditional expression) {

The interval to be executed when the conditional expression is established;

}else{

The conditional expression is not an interval to be executed immediately;

}

Execution process:

1. First to determine whether the conditional expression is set up, if it is established, the execution of the conditions of the implementation of the interval

2. If the conditional expression is not true, then the non-established interval in the curly braces after else is executed

c) Multidirectional branching structure One

IF (conditional expression 1) {

Expression 1 is set to perform interval one

}else if (conditional expression 2) {

Expression 2 is set to execute interval two

}else if (conditional expression N) {

Expression n is set to execute interval n

}else{

If none of the above conditional expressions are true, this interval is executed

}

Execution order

1. Determine whether the conditional expression 1 is established

2. If it is established, the implementation interval

3. If not, continue to determine whether the conditional expression 2 is established

4. If set up, perform interval two

5. If not, continue to determine whether the conditional expression N is set

6. If it is set up, execute interval n

7. If all of the above conditions are not true, then the interval behind the else is executed

d) Multi-directional branching structure two

Switch (variable) {

Case Value One:

Process one;

Break

Case Value Two:

Process two;

Break

Case Value N:

Process N;

Break

Default

If none of the preceding values are met, this interval is executed

Break

}

Iv. Order of execution:

1. Preferred to determine whether the variable behind the switch exists, if there is

2. Determine what the value of the variable is, and then look for the eligible partial execution from the case branch

3. If all case branching conditions are not met, then the part of the default is executed

V. Precautions:

1. The value of the variable following the case, which needs to match the type of the variable

2. The symbol behind the case is a colon:

3. At the end of each case branch, it is necessary to add a break to the end condition

e) Nest-like branching structure

If (outermost condition expression) {

If (inner conditional expression) {

if (most inner condition expression) {

program Body;

}

}

}

III. Order of execution:

1. First determine whether the outermost conditional expression is true, and if so, to execute the inner-layer conditional expression!

2. Note: Nesting of nested branching structures should not exceed three layers, which is the "charm" principle in PHP

Third, the cycle structure

A) The cycle of life, such as our daily meals, we want to eat meals a day, we need to have a condition in line with, we must live well, when living this condition is not established, the cycle stopped

b) Rule: cycle if you want to keep going, there must be a condition that is in compliance, if the condition does not meet, then terminate the loop!

c) While loop:

while (conditional expression) {

Circulation body;

self-increasing conditions;

}

III. Order of execution:

1. First to determine whether the conditional expression is set up, if it is established, then the contents of the loop body, then to ask whether the conditional expression is set up, if it is still true, continue to execute the contents of the loop body, has been circulating to the conditional expression is not established.

Iv. Precautions:

1. The Wihle cycle usually determines whether a conditional expression is formed

2. If this piece of self-increment or self-reduction is involved, we need to cooperate with + + or--use

3. Pay attention to the emergence of the dead cycle, the death cycle in time to terminate the program

d) Do...while cycle:

do{

Circulation body;

The condition of self-increment or self-reduction;

}while (conditional expression);

III. Order of execution:

1. Executing the contents of the loop body

2. Determine if the conditional expression is true

3. If established, continue to execute the contents of the loop body

4. If not, jump out of the loop

Iv. Precautions:

1. Structure writing format, while the semicolon must be written in the back, otherwise it may be wrong

2. Note that this piece relates to self-increment and decrement, which needs to be combined with + + and – using

3. Pay attention to the emergence of the dead cycle, there must be a dead cycle to terminate the program in time

V. Summary: While loops and do...while loops are commonly used for conditional expression judgments

A) for loop:

Standard structure:

for (expression 1; expression 2; expression 3) {

Circulation body;

}

Special structure:

Expression 1;

for (; expression 2;) {

Circulation body;

Expression 3;

}

VI Expression meaning:

1. Expression 1 represents the assigned initial value

2. Expression 2 represents the condition

3. Expression 3 represents the self-increment or self-reduction

Vii. Order of execution:

1. First execute expression 1 to assign an initial value

2. Then determine if the expression 2 meets the criteria

3. Executing the contents of the loop body

4. After execution, go back to the expression 3 self-increment or decrement

5. Again to determine whether the expression 2 meets the criteria

Viii. Precautions:

1. Order of execution to be clear

2. Use a semicolon between the 3 expressions in the For loop parenthesis ";" Separated, the last expression without a semicolon

3. For loop can be nested, but not more than 3 layers

4. Note The file code you wrote, and whether the file you executed is the same file

b) Special flow control statements:

I.break statements

1. In the switch branch, the delegate ends a branch

2. In the loop if a layer loop encounters a break statement, it represents a direct termination of the current loop

Ii. Continue statements

1. In the loop if a layer loop encounters a continue statement, it represents a loop that jumps out of the current layer, but continues the next layer of loop

Iii. die Statements

1. Can terminate the execution of the entire script

2. It has the same meaning as exit, except that the name is not the same

3. We can use the Die statement or the exit statement to debug the code

iv. Exit statement

function Ibid.

"PHP" Process Control

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.