In the process of developing software, sometimes it is necessary to flexibly use various forms of the for statement. Now, other forms of the for statement are listed in the form of sample code!
//The first change is to extract the first part of the for loop syntax
$i=1;
for(; $i<2; $i++){ //The first semicolon cannot be omitted
echo "This is the ".$i."th output!";
}
?>
//The second change is to extract the first part of the for loop syntax and put the increment of the third part into the for loop body
$i=1;
for(; $i<2; ){ //The first semicolon cannot be omitted
echo "This is the ".$i."th output!";
$i++;
}
?>
//The third change is to omit all the for loop syntax
$i=1;
for(; ; ) { //The first semicolon cannot be omitted
if($i>1)
break;
echo "This is the ".$i."th output!";
$i++;
}
?>
All programs run on Apache 2.2+PHP5.2.6!
If you are poor, you will change, if you change, you will be general, and if you are general, you will be successful. It seems that this philosophy also exists in the program!
Excerpted from chuoyue05’s column