Page 1 of 1

el grande for/while loop problem..........that means big

Posted: Wed Mar 10, 2004 1:14 pm
by dull1554
here's a snipett of code for a bj game im working on at the moment

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++;
}
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

Posted: Wed Mar 10, 2004 5:59 pm
by scorphus
Can you tell us which of the four loops never ends? The 1st for, the 2nd for, the while or the 3rd for?

Thanks.
Scorphus.