+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: if()

  1. #1
    vTurato is offline x10Hosting Member vTurato is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    1

    if()

    You only use braces if it's more than one line in an if statement

  2. #2
    tittat's Avatar
    tittat is offline x10 Spammer tittat is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Kerala,India
    Posts
    2,479
    Sorry, but i didn't get you.....
    Do you want any help regarding "if" statements.???

    *****Thread Moved to Programming Help*****
    Last edited by tittat; 02-19-2009 at 07:12 AM.
    PLAY ONLINE GAMES
    WWW.TMONDO.COM PlayFar Flash Games
    Former X10 Forum Senior Moderator(Retired)


  3. #3
    ichwar's Avatar
    ichwar is offline Community Advocate ichwar is an unknown quantity at this point
    Join Date
    Dec 2008
    Location
    NC, USA
    Posts
    1,454

    Re: if()

    vTurato, that's not totally true. the syntax is:

    Code:
    if(condition)
    {
    action
    }
    Last edited by ichwar; 02-19-2009 at 01:38 PM.

  4. #4
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: if()

    just to clarify if() has two possible syntax

    if the action clause is in a single line:
    PHP Code:
    if(argumentaction
    or
    PHP Code:
    if(argument) {action;} 
    or if it spans over multiple lines:
    PHP Code:
    if(argument){
      
    action1;
      
    action2;


  5. #5
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: if()

    ichwar, he is actually correct. If you've only got one line after the if statement, you don't need braces.

    PHP Code:
    if ($value == true)
      echo 
    "Hi";
    else
      echo 
    "Bye"

  6. #6
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: if()

    Just to add to diablo's points (which are correct)..

    "One line" should read "one command", followed by a semi colon;

    i.e. echo "something";

    This can be done either on the same program line or with a return.

  7. #7
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: if()

    syntax readability wise, it's better to use one line for everything when there is one command
    PHP Code:
    if(argumentaction
    and braces when there is many commands
    PHP Code:
    if(argument){
      
    action1;
      
    action2;

    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  8. #8
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: if()

    Quote Originally Posted by xav0989 View Post
    syntax readability wise, it's better to use one line for everything when there is one command
    PHP Code:
    if(argumentaction
    and braces when there is many commands
    PHP Code:
    if(argument){
      
    action1;
      
    action2;

    I disagree.
    I think it is better to put the execution statement on a separated line to the condition statement. Indented, of course. That way, it becomes far more clearer to distinguish the condition and statement, and to match them up.

    But of course, everyone works in a different way, and when it comes down to a difference in [parser ignored] whitespace, the final effect will be no different.
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  9. #9
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: if()

    Not to contradict you, but when you work on projects with dozen of 1000 lines pages, you prefer the one line statements, although to indent everything might seem nicer.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  10. #10
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: if()

    Stop arguing, because it's an opinion. My preference is the same as Schoochi, but it's just a preference.

    I've got some scripts that are over 1000 lines and i think it's easier to distinguish conditionals, because it's a new tab and not the same line.


    PHP Code:
    if ($act == "main")
    {
        echo 
    "hi";
        if (
    $logged) echo "welcome";
        
    $a*5;

    vs
    PHP Code:
    if ($act == "main")
    {
        echo 
    "hi";
        if (
    $logged)
            echo 
    "welcome";

        
    $a*5;


+ Reply to Thread
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers