Three major process controls for PHP programs

Source: Internet
Author: User

Three major process controls for PHP programs

① sequential control (top to bottom). From 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 a lot of other else if

else{

}

U Switch Branch statement

The basic grammatical structure

switch ( expression ) {

Case Constants 1:

//n Multi-statement ;

Break

Case Constants 2:

//n Multi-statement

Break

Default

//n Multi-statement ;

Break

}

u types of constants (int, float, string , boolean, and null

default you can put it anywhere.

The right side will output hello12 .

conclusion: First, according to Case order to match, assuming none of the matches

to, then run default , until you encounter Break or }

Application scenario: When our branch is a few points (for example, to infer the direction of a tank), you should use Swtich, assuming that your branch is inferred from several regions (ranges). Then consider using IF.

Cycle Control Flow

For ( Cyclic initial value ; conditions of the cycle ; Step Size ){

//n Multi-statement ;

}

While ( loop condition ) {

// Loop Body , Statement

}

do{

       // Loop Body

}while ( cyclic conditions );

42, We follow the normal thinking should be guaranteed to accept the data when the $_request[' " " to and submit the data page The HTML element name to be consistent. If the assumptions are inconsistent, a notice prompt appears.

The data we accept at the same time is null, equivalent to "".

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

43. Break and Continue

U Loop-related statement-break

Main concept: Indicates the end of the current for, while, do. While,switch, process , can give a number, indicating exit to the first layer .

$i = 0;

while (+ + $i) {

Switch ($i) {

Case 5:

echo "Quit At5<br/>";

Break

Case 10:

echo "Quitat 10<br/>";

Break 2;

Default

Break

}

}

echo ' $i = '. $i;

The result is:

Quit at 5
Quit at 10
$i =10

From the above case, we get a few conclusions:

1. Break statement jumps out of layer 1 by default

2. The number after the break statement. Cannot exceed the number of loop layers that can actually jump out. Otherwise. Will report FatalError

? Circular related Statements-continue

Basic concept: The Continue is used to end the remainder of this cycle of code. Start a new cycle (assuming the condition is true and continue running),continue can also be followed by numbers, indicating that the first cycle starts again

Three major process controls for PHP programs

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.