Re: count up from 7

From: Date: Tue, 25 Mar 2003 11:22:17 +0000
Subject: Re: count up from 7
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-140934@lists.php.net to get a copy of this message
Richard -- ..and then Richard Whitney said... % % Braindead! Hey, who are you callin' names?!? % % I need to evaluate a number if greater than 7 and add a value per increment. Greater than seven is easy. Adding a value is easy. Per increment can be a little tricky but we'll assume for the moment that the window is 1. The code $sum = 67 ; # starting value $trg = 7 ; # trigger value $add = 6 ; # what we add each time $num = 10 ; # what we're evaluating (hardcoded here!) for ( $num ; $trg < $num ; $trg++ ) { $sum += $add ; } print "when num = $num, sum = $sum\n" ; should do for a starting point, though, and produces bash-2.05a$ php -q /tmp/inc.php when num = 10, sum = 85 bash-2.05a$ php -q /tmp/inc.php when num = 20, sum = 145 bash-2.05a$ php -q /tmp/inc.php when num = 7, sum = 67 bash-2.05a$ php -q /tmp/inc.php when num = 1, sum = 67 when run. Extra credit if you write it as a recursive function :-) % I'm frazzled and can't think straight. You can't ask straight, either :-) Give us more details! % % Thanks Guys! HTH & HAND :-D -- David T-G * There is too much animal courage in (play) davidtg@justpickone.org * society and not sufficient moral courage. (work) davidtgwork@justpickone.org -- Mary Baker Eddy, "Science and Health" http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

« previous php.general (#140934) next »