PHP Process Control Statements

Source: Internet
Author: User
Tags php programming php programming language

Php
Process Control Statement (top)
In the PHP programming language, there are 3 basic structure, divided into sequential structure, branching structure and loop structure.
Provide four flow control statements in PHP to implement branching and looping structures.
1.if........else ... Conditional statements
2.switch Branch Selection Statement
3do....while .... Loop statement
4.for Loop statement
Let's look at the usage of 4 flow control statements
One, If........else ... Conditional statement {If........else ... a total of three structure, in addition to each of the basic structure can also nest two other structures, but also can be granted multilevel nesting}
1. Only if statements
This structure can be understood as "what to do if a condition is established" with the following syntax:
if (expr) {
Sattement
}
2.if........else .... statement

This structure can be interpreted as "what to do if a condition is established, or to do another thing." "Its syntax is as follows:
if (expr) {
Statement1
}else{
Statement2
}
If Statement1

To do it for real, not to do it for real 2,
3. Statements that contain else if
Use the else if to implement the Multipath branch, which is expressed in syntax as follows:
if (expr) {
Statement1
}else ifexpr2) {
Statement2
}
Else
Statement
)
If the statement1 is true, do not perform 2, and so on, or execute statement.

two,  
Switch statement  
nested if...else .... The statement can handle the multi-out branching process, but it is cumbersome and less clear, and introduces a switch statement for the mating breed. The syntax is as follows p: 
Switch (expr|) { 
case ecpr1: 
statement1: ,
break: 
case exp2: 
statement2: 
break: 
.  
.  
.  
default: 
statementn: 
break: 
Where expr is the condition, the usual variable name. The EXPRN after the case, usually indicates that the value of the variable after the colon is to meet the criteria to execute the statement, it is important to note that the role of break to exit the switch structure, can not omit to write,


Loop control Statements
One, Do........while ... Statement
In PHP, Do........while. There are two structures in a looping statement, one of which is only while ... part, the other is do........while. There are two parts.
1. Only while ... part of the statement
As follows:
while (expr) {
Statement
}
2.do........while .... Both parts have statements.
As follows:
do{
Statement
}
while (expr):
The condition in which expr is judged is usually a logical expression or a comparison expression. While the statement executes part of the program for qualifying amounts, the curly braces {} can be omitted if the program has only one line.
The difference between the two results is that the former is the first to judge the conditions in the execution of the statement, after the first to judge the case of expr begins to be true, the two structures are no difference, if the result is no difference, if expr starts false, then the former does not execute any statements to jump out of the loop, the latter still have to execute a loop


This article from the "New Network Society Blog" blog, reproduced please contact the author!

PHP Process Control 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.