You are here: Re: Recursionalism « PHP Programming Language « IT news, forums, messages
Re: Recursionalism

Posted by gosha bine on 05/04/07 07:43

On 04.05.2007 05:36 Mohawk Moak wrote:
> this method worked good, i did not realize to set the global twice.
> the reason to set the counter to 0 in the end is so that the function
> is usable more than 10 times (or whatever limit it is)
> thanks for pointing out that it was in the wrong row though xD
> probably would not have figuered that one out so fast
> bless
>

Actually, you only need 'global' once: inside the function. Moreover,
even this is not really necessary - using global variables is considered
bad practice and it's better to avoid them from the beginning. This is
how you can rewrite your function without globals:

function recursion($value, $counter = 0){
$counter++;
if ($counter > 10){exit("Recursion exceeded limit!");}

$newvalue= blabla something with $value

if (condition applies){recursion($newvalue, $counter);}
return $newvalue;
}


--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация