Re: BUG in recursion
| From: | Tom Rogers | Date: | Tue, 02 Apr 2002 07:45:32 +0000 |
| Subject: | Re: BUG in recursion | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-91090@lists.php.net to get a copy of this message | ||
Hi
One way is to use a variable to track the recursion llike this:
<?
function Test($max){
static $count = 0;
static $y = 0;
$count++;
$y++;
echo $count;
if ($count < $max) {
Test($max);
}
$y --;
if($y == 0){
echo "j";
}
}
test(10);
?>
$y will always be 1 as long as it is in recursion only going to 0 on the last one.
Tom
At 09:59 AM 31/03/2002, Uros Gruber wrote:
Hi! This is a code function Test() {static $count = 0;$count++; echo $count; if ($count < 10) { Test (); } echo "j";} test(); Output is 12345678910jjjjjjjjjj Why is there 10 j at the and. If this would work it can be only one. If $count is grater than 10 it does not call itself but end. Is this maybe a bug or what. -- lp,Uros mailto:uros.gruber@sir-mag.com-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php