# PHP help



## Hale88 (Nov 26, 2009)

I am learning While...loops... and I have got everything so far except for one.

How can I do SUM in while...loops statement?

Ex: I have a number call: $number = 1, I know how to list from 1-10

but I don't know how to SUM them all together to get a Total of 55 (1+2+3...+10 = 55)?

help me please!
thank you
hale


----------



## FordGT90Concept (Nov 26, 2009)

```
$number = 1;
$total = 0;
while ($number <= 10)
{
  $total += $number;
  $number++;
}
```
Not tested but should work.  FYI, a for loop is better suited to this than a while loop.


----------



## Hale88 (Nov 26, 2009)

Hey I got it work:

 print "Use While loop to calculate the sum: 1-10:";
        print "<br/>";
        $number = 1;
        $total = 0;

        for ($number =1; $number <= 10; $number++)
        {
         print "$number <br/>" ;

         $total += $number;
            }
        Print "The Total is :$total";


        ?>

thank for helping


----------

