Re: if else while statement speed
| From: | Chris Sherwood | Date: | Wed, 03 Sep 2003 17:49:57 +0000 |
| Subject: | Re: if else while statement speed | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-161578@lists.php.net to get a copy of this message | ||
have you thought about usiing a switch statement that way all the if or else
if statements are not checked against?
ie
<?php
while (something())
{
switch($option)
{
case $option1:
break;
case $option2:
break;
case $... etc
break;
}// end of
}
> if ($option1)
> { do_1(); }
> elseif ($option2)
> { do_2(); }
> // ... continue for 10 or more options...
> }
> ?>
----- Original Message -----
From: "Dan Anderson" <dan@mathjunkies.com>
To: "PHP List" <php-general@lists.php.net>
Sent: Wednesday, September 03, 2003 10:25 AM
Subject: [PHP] if else while statement speed
> I have a function where I have:
>
> <?php
> while (something())
> {
> if ($option1)
> { do_1(); }
> elseif ($option2)
> { do_2(); }
> // ... continue for 10 or more options...
> }
> ?>
>
> would it be quicker to do the above code or:
>
> if ($option1)
> {
> while(something())
> { do_1(); }
> }
> elseif ($option2)
> {
> while (something())
> { do_2(); }
> }
> // ... continue for 10 or more options...
>
> Thanks,
>
> Dan
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>