Three main flow control of PHP program

Source: Internet
Author: User
Tags constant continue end expression

Three main flow control of PHP program

① sequential control (from top to bottom, left to right)

② Branch Control

if (conditional expression) {

N Multiple statements

}else if (conditional expression) {

N Multiple statements

}else if (conditional expression) {

//.

}//there may be more else if

else{

}

U Switch Branch statement

Basic grammatical structure

switch (expression) {

CASE constant 1:

n multiple statements;

Break

Case constant 2:

N Multiple statements

Break

Default

n multiple statements;

Break

}

the type of the U constant (int, float, string, Boolean, and null

You can keep the default wherever you go.

The right side will output hello12.

Conclusion: first match according to case order, if none of them match

, the default is executed until a break is encountered or}

Application scenario: When our branch is a few points (for example, to determine the direction of a tank), you should use Swtich, and if your branch is judged by several areas (ranges), consider using IF.

Cycle Control Process

For (cyclic initial value; loop condition; step size) {

n multiple statements;

}

while (loop condition) {

Loop body, statement

}

do{

Circulation body

}while (cyclic conditions);

42, we in accordance with the normal thinking should be guaranteed to accept the data when $_request[' parameters ' to the submission of data page to give the name of the HTML element to be consistent. If it is inconsistent, a notice prompt appears. And the data we accept is null, equivalent to "".

$_request This method can accept the user's post or GET request data

43. Break and Continue

U -Loop related statements-break

Basic concept: Represents the end of the current for, while, do. While, switch, process, you can give a number that represents the exit to the first level.

$i = 0;

while (+ + $i) {

Switch ($i) {

Case 5:

Echo Quit AT5
;

Break

Case 10:

Echo Quitat 10
;

Break 2;

Default

Break

}

}

echo ' $i = '. $i;

The result:

Quit at 5
Quit at 10
$i =10

From the above case, we have several conclusions:

1. Break statement default jump out of 1 layer

2. The number after the break statement, can not exceed the actual number of loops to jump out, otherwise, will report FatalError

Ø Circular related statements-continue

Basic concept: Continue is used to end this cycle of remaining code, to start a new cycle (if the condition is true, continue to execute), continue can also be followed by a number, indicating from the first several loops restart



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.