Php process control statements and loop control statements (explanation)
1. Flow Control statements include if, ii... else, elseif (sometimes else if), and switch.
The statement format in PHP is:
If (condition met) {execution statement}
If (condition met) {execution statement} else {execution statement}
If (condition met) {execution statement} elseif {execution statement} ...... else {execution statement}
Switch (condition) {case 1: Statement; break;
Case 2: Statement; break;
Case 3: Statement; break;
Default: Statement; break ;}
If: only one condition exists.
If... else: two conditions exist.
Elseif: there are multiple conditions
Switch: when multiple conditions exist, the elseif statement works the same as the switch statement. To avoid complicated and lengthy statements, use the switch statement
2. There are three types of loop control statements: while, for, and do while. For example, All integers smaller than 5 are output.
The statement format in PHP is:
* ****** While statement *******
$i = 0; while($i<5) { echo $i; $i++; }
* ****** For statement *******
for($i = 0;$i < 5;$i++) { echo $i; }
* ***** Do while statement *******
$i = 0; do { echo $i; $i++; }while($i<5);
Note]
1. The while LOOP does not know the number of cycles, and the for loop knows the number of cycles.
2. A complex PHP code may contain multiple condition control statements, loop control statements, and functions. It is very troublesome to find matching braces. To this end, PHP provides another writing format, including if, while, for, foreach, and switch. The basic form of writing this form is: Use the colon ":" to replace the braces "{" on the left, use endif;, endwhile;, endfor;, endforeach;, endswitch; to replace the braces "}" on the right.
[Keyword]
Break: terminate a loop
Continue: Terminate the loop and continue the next loop until the loop ends.
The above php-based process control statements and cyclic control statements (explanations) are all the content shared by Alibaba Cloud. I hope you can give us a reference and support for the customer.