Home  >  Article  >  php教程  >  PHP1到100求和各种实例程序

PHP1到100求和各种实例程序

WBOY
WBOYOriginal
2016-06-13 10:17:161619browse

本文章来给各位同学收藏了一些不错的PHP1到100求和各种实例程序,希望对大家有所帮助。

PHP1到100求和方法集锦,有很多方法都可以实现,先讲一下最简单的几种方法,比如用FOR,WHILE等循环语句求和

FOR循环语句1到100求和方法

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

WHILE循环语句1到100求和方法

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

DO-WHILE循环语句1到100求和方法

 代码如下 复制代码
$i=1;
$sum=0;
do{
$sum+=$i;
$i++;
}
while ($i echo $sum;
?>
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