Home  >  Article  >  Backend Development  >  Various example programs for summing PHP1 to 100_PHP tutorial

Various example programs for summing PHP1 to 100_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:16:251596browse

This article collects some good PHP1 to 100 summation example programs for you. I hope it will be helpful to everyone.

A collection of PHP summing methods from 1 to 100. There are many ways to achieve it. Let’s talk about the simplest methods first, such as using FOR, WHILE and other loop statements to sum up

FOR loop statement 1 to 100 summing method

 代码如下 复制代码
$sum=0;
for($i=1;$i<=100;$i++){
$sum+=$i.'
';
}
echo $sum;
?>

WHILE loop statement 1 to 100 summing method

 代码如下 复制代码
$i=1;
$sum=0;
while ($i<=100) {
$sum = $sum +$i;
$i++;
}
echo $sum;
?>

DO-WHILE loop statement 1 to 100 summing method

 代码如下 复制代码
$i=1;
$sum=0;
do{
$sum+=$i;
$i++;
}
while ($i<=100);
echo $sum;
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628644.htmlTechArticleThis article has collected some good PHP1 to 100 summation example programs for you. I hope it will be helpful to everyone. Helps. A collection of PHP summing methods from 1 to 100. There are many ways to achieve it. First...
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