Implementation of PHP Basic Learning Process Control

Source: Internet
Author: User
Tags case statement

PHP has three major process controls: sequential control, branch control, and cyclic control.

1. Sequential Control: YesProgramPerform the preceding steps in sequence.

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 statement can be absent (based on your own)CodeBusiness Logic) 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

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.