Home  >  Article  >  Backend Development  >  Changes in the for statement_PHP tutorial

Changes in the for statement_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:50:491250browse

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478247.htmlTechArticleIn the process of developing software, sometimes it is necessary to flexibly use various forms of the for statement. Now let’s put the other forms of the for statement The form is listed in the form of sample code! //The first change is to change the for loop syntax...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn