Re: Setting execution time for a loop
| From: | zavaboy | Date: | Wed, 10 Sep 2003 11:14:01 +0000 |
| Subject: | Re: Setting execution time for a loop | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-162155@lists.php.net to get a copy of this message | ||
if I wait untill $sDate is zero, it'll be in 2000.
I have $Date based on the current date, like to day is: 03252
03 is the year 252 is the day of the year.
"Mike Ford" <M.Ford@lmu.ac.uk> wrote in message
news:841D90E489448A4F804E1D1B95768BF7D461DD@lis-exchange3.lmu.ac.uk...
> On 10 September 2003 11:26, zavaboy contributed these pearls of wisdom:
>
> > // Ok, I have a loop:
> > for ($i = $Date; $i >= $sDate; $i--)
> >
> > // Somthing like this is inside the loop:
> > if ($Exists)
> > echo "Something here.";
> > else
> > $sDate--;
> >
> > I have it check if it exists, if it doesn't, then it reduces
> > $sDate by 1. $sDate is initially 3 to 31 days less than $Date.
> > By reducing $sDate by 1, it keeps looking, what if there are
> > no more? It keeps going until I reach 30 seconds, how can I
> > set a time limit?
>
> No need to set a time limit for this -- just set a limit on how far $sDate
> can be decremented. Presumably only positive values are invalid, so just
> stop the loop when $sDate goes <=0 -- either
>
> for ($i = $Date; $i >= $sDate && $sDate > 0; $i--)
>
> or something like:
>
> for ($i = $Date; $i >= $sDate; $i--):
>
> if ($Exists):
> echo "Something here.";
> else:
> $sDate--;
> if ($sDate<=0):
> // do any necessary tidying up here -- e.g. set a
> // flag to say the loop was exited via the side door
> break; // escape from the for loop
> endif;
> endif;
>
> endfor;
> // break escapes to here
>
> Cheers!
>
> Mike
>
> ---------------------------------------------------------------------
> Mike Ford, Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Beckett Park, LEEDS, LS6 3QS, United Kingdom
> Email: m.ford@lmu.ac.uk
> Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211