SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot amit290's Avatar
    Join Date
    Oct 2001
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Good practice putting ELSE with IF statement?

    Hi,

    I was just wondering, is it good practice to always put ELSE with an IF statement?? There are some situations where you dont really want the script to do something else, if the statement is true or not. i.e.

    PHP Code:
    if($variable == "yes") {
        
    //this equals yes, echo text
        
    echo "Hello";
    } else {
        
    //do nothing
    }
     
    <
    p>Some HTML goes here</p
    or
    PHP Code:
    if($variable == "yes") {
        
    //this equals yes, echo text
        
    echo "Hello";
    }
    <
    p>Some HTML goes here</p

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would say it's bad practice to include an ELSE statement if you don't need one.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah! precisely, why put more parse load on the interpreter

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No, you only need to put the else if there is a second statement you want processed if the equation is not valid.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •