This article to the students to collect some good PHP1 to 100 summation of various instances of the program, I hope to help you.
PHP1 to 100 summation method collection, there are many ways can be achieved, first of all, the simplest of several methods, such as the use of for,while and other circular statements summation
For loop statements 1 to 100 summation method
| The code is as follows |
Copy Code |
$sum = 0;
for ($i =1; $i <=100; $i + +) {
$sum + = $i. '
';
}
Echo $sum;
?> |
While loop statement 1 to 100 summation method
| The code is as follows |
Copy Code |
$i = 1;
$sum = 0;
while ($i <=100) {
$sum = $sum + $i;
$i + +;
}
Echo $sum;
?> |
Do-while loop statements 1 to 100 summation method
| The code is as follows |
Copy Code |
$i = 1;
$sum = 0;
do{
$sum + = $i;
$i + +;
}
while ($i <=100);
Echo $sum;
?> |
http://www.bkjia.com/PHPjc/628644.html www.bkjia.com true http://www.bkjia.com/PHPjc/628644.html techarticle This article to the students to collect some good PHP1 to 100 summation of various instances of the program, I hope to help you. PHP1 to 100 summation method collection, there are many ways to achieve, first ...