Hey everybody this is my first post here and just learning PHP and need some help on an infinite loop problem. The code is supposed to find how many ways you can change a $1 dollar bill into coins using dollar coin, half dollars, quarters, dimes, nickels, and pennies. But i am having a problem because it is timimg out my browser and i asked my instructor and he said i have a infinite loop. I honestly dont have a clue what to look what when i comes to this.
Heres the code:
<?php
//Setting all coins to 0
$loopCounts = 0;
$numDollars = 0;
$numHalfs = 0;
$numQuarters = 0;
$numDimes = 0;
$numNickels = 0;
$numPennies = 0;
//What the max number of each coin can be to make a $1.00
$maxDollars = 1;
$maxHalfs = 2;
$maxQuarters = 4;
$maxDimes = 10;
$maxNickels = 20;
$maxPennies = 100;
//The value of what each coin is worth
$valDollar = 100;
$valHalf = 50;
$valQuarter = 25;
$valDime = 10;
$valNickel = 5;
$valPenny = 1;
print("<table border=\"2\"> ");
print("<tr><td>Number</td><td><strong>Dollars</strong></td><td>
<strong>HalfDollars</strong></td><td><strong>Quarters</strong></td><td><strong>Dimes</strong></td><td><strong>Nickels</strong></td><td><strong>Pennies</strong></td></tr>");
//Beginning of the loops
FOR ($numDollars =0; $numDollars <= $maxDollars; $numDollar++)
{
FOR ($numHalfs =0; $numHalfs <= $maxHalfs; $numHalfs++)
{
FOR ($numQuarters =0; $numQuarters <= $maxQuarters; $numQuarters++)
{
FOR ($numDimes =0; $numDimes <= $maxDimes; $numDimes++)
{
FOR ($numNickels =0; $numNickels <= $maxNickels; $numNickels++)
{
FOR ($numPennies =0; $numPennies <= $maxPennies; $numPennies++)
{
$loopCounts = $loopCounts + 1;
$coinSum = ($numDollars * $valDollar) + ($numHalfs * $valHalf) + ($numQuarters * $valQuarter) + ($numDimes * $valDime) + ($numNickels * $valNickel) + ($numPennies * $valPenny);
IF ($coinSum == 100)
{
$goodCombo = $goodCombo + 1;
print("<tr><td>$goodCombo</td><td>$numDollars</td><td>$numHalfs</td><td>$numQuarters</td><td>$numDimes</td><td>$numNickels</td><td>$numPennies</td></tr>");
}//end if
}//end FOR loop for Pennies
}//end FOR loop for Nickels
}//end FOR loop for Dimes
}//end FOR loop for Quarters
}//end FOR loop for Half Dollars
}//end FOR loop for Dollar Coin
print("<p>There are $loopCounts you can make change for One Dollar</p>");
print("</table>");
?>
It would be a big help if yall could help me look for it because I have know idea what to look for. Thank you for your time.