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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

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

Post 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
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post 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.
Post Reply