Re: Which is quicker, if-else statements
| From: | Philip Hallstrom | Date: | Tue, 18 Mar 2003 20:09:45 +0000 |
| Subject: | Re: Which is quicker, if-else statements | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-140180@lists.php.net to get a copy of this message | ||
> Is it just as quick to do:
>
> if($r == 0) {
> } else if($r != 0) {
> }
>
> than to do:
>
> if($r == 0) {
> } else {
> }
>
> The reason I like the former method is because, in a large IF-ELSE
> block, it's clear what belongs to what IF and what's going on. But does
> this make it lag? And, if so, is it really all that noticeable?
I don't know which is actually quicker, but I would guess that the first
case would take longer since it PHP has to evaluate "$r != 0" instead of
just doing whatever is in the "else { ... }" clause.
If you want clarity, why not:
if($r == 0) {
...
} else { // $r != 0
}
that gets you the clarity, but keeps PHP from having to evaluate it.