Things You'll Need:
- MySQL database server
- Web server
- PHP 5
- PHP IDE
-
Step 1
Define the variables you will use, then assign them an initial value:
$count = 1;
$total = 15; -
Step 2
Write the expression that is to be evaluated when the loop begins. Note that this expression includes the action that must be performed if, at the end of the loop, the condition is still true. In this case, the action will increment the count variable:
for ($count = 1; $count <= 10; $count++) -
Step 3
Write the action that must be performed:
{
$total = $total + $count;
echo "The total amount is $total
";
} -
Step 1
Double-check to make sure your code looks like this:
$count = 1;
$total = 15;
for ($count = 1; $count <= 10; $count++)
{
$total = $total + $count;
echo "The total amount is $total
";
} -
Step 2
Check for syntax errors and run the code. It must check to see if the count value is less than or equal to 10. When it is less than or equal to 10, its value will be incremented by 1, and then the new value will be used to calculate the total value. The loop continues while the count is less than or equal to 10.











