Re: Which is quicker, if-else statements
| From: | Chris Shiflett | Date: | Tue, 18 Mar 2003 20:21:38 +0000 |
| Subject: | Re: Which is quicker, if-else statements | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-140184@lists.php.net to get a copy of this message | ||
--- Liam Gibbs <liamgibbs@sympatico.ca> wrote:
> Is it just as quick to do:
>
> if($r == 0) {
> } else if($r != 0) {
> }
>
> than to do:
>
> if($r == 0) {
> } else {
> }
No. It is (almost) the difference between two conditionals versus one. Both are
fast, however, and you will find it hard to measure the difference unless you
have many instances of this.
If you're concerned about performance, you should also use notation such as if
(!$r) instead of if($r == 0). If you're concerned about readability, consider a
comment near your else statement that explains what condition fits there.
Chris
=====
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/