el grande for/while loop problem..........that means big
Posted: Wed Mar 10, 2004 1:14 pm
here's a snipett of code for a bj game im working on at the moment
every time i run the script the loop never ends, i can go as far as to tell you what has to happen, i know the soultion just not how to implement it. after the loop runs it needs to update the $dcvt total, but it is not so it loops to no end, does anyone know how i can fix this or have a better way of doing this
Code: Select all
for($dcards = 2; $dcvt < $goal; $dcvt = array_sum($dcv))
{
for($i = 1; $i < 2; $i++)
{
$suit = mt_rand(1,4);
$card = mt_rand(1,13);
$dcs[$dcards+1] = $suit;
$dcn[$dcards+1] = $card;
}
while(($dcs[$dcards+1]+$dcn[$dcards+1] == $pcs+$pcn) || ($dcs[$dcards+1]+$dcn[$dcards+1] == $dcs+$dcn))
{
for($i = 1; $i < 2; $i++)
{
$suit = mt_rand(1,4);
$card = mt_rand(1,13);
$dcs[$dcards+1] = $suit;
$dcn[$dcards+1] = $card;
}
}
$dcards++;
}