How to use flow Control statement and Loop Control statement based on php
This article will explain in detail how to use php-based process control statements and loop control statements. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
1. There are mainly four kinds of process control statements: if, ii...else, elseif (sometimes it can be written as elseif) and switch.
The format of the statement in PHP is:
If (condition satisfied) {execute statement}
If (condition satisfied) {execute statement} else {execute statement}
If (condition satisfied) {execution statement} elseif {execution statement} elseif {execution statement}. Else {execute statement}
Switch (conditional) {case 1: statement; break
Case 2: statement; break
Case 3: statement; break
Default: statement; break;}
If: there is only one condition
If...else: there are two conditions
Elseif: there are multiple conditions
Switch: multiple conditions when multiple conditions, elseif and switch statements have the same effect. However, in order to avoid complicated and lengthy sentences, use the switch statement
2. There are mainly three kinds of loop control statements: while, for and do while. For example, output all integers less than 5.
The format of the statement in PHP is:
* while statement *
I = 0; while ($I