+ Reply to Thread
Results 1 to 6 of 6

Speed/Efficiency for If-Else Construct

  1. #1
    Registered User
    Join Date
    03-31-2009
    Location
    Auburn Alabama
    MS-Off Ver
    Microsoft Office Excel 2007 (Windows)
    Posts
    99

    Speed/Efficiency for If-Else Construct

    Hello,

    My question is about the If-Else Construct.

    I often write If-Else statements that require an action be taken only if something is true. If that something is false, no action is to be taken.

    My question is, how do you code "no action".

    The following is what i usually code:

    Please Login or Register  to view this content.
    As you see above, when false, I usually just assign the variable the value it already has. That's because I want nothing to happen if the result is false.

    But isn't that a waste of time for my program? Am i not just giving my processor one more thing to do for no reason. Slowing down my program with unnecessary assignments?

    If so, what are my alternatives? Is there a common programming strategy that all programmers adhere to in this situation? I mean, do I just put nothing after the Else Construct (except for a maybe a comment noting the nothingness was intentional)? Hmmm...

    Thanks for any help! Trying to be efficient here
    Last edited by CrazyFileMaker; 04-21-2009 at 04:54 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Speed/Efficiency for If-Else Construct

    If no Else is required you can use one line, eg:

    Please Login or Register  to view this content.
    No Else/End If required

    Another alternative to the above in this context:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-31-2009
    Location
    Auburn Alabama
    MS-Off Ver
    Microsoft Office Excel 2007 (Windows)
    Posts
    99

    Re: Speed/Efficiency for If-Else Construct

    Makes perfect sense!

    Thanks DonkeyOte!!

  4. #4
    Registered User
    Join Date
    03-31-2009
    Location
    Auburn Alabama
    MS-Off Ver
    Microsoft Office Excel 2007 (Windows)
    Posts
    99

    Re: Speed/Efficiency for If-Else Construct

    Hi again,

    What if I have two actions that need to be taken?

    Please Login or Register  to view this content.
    Will it still work without the Else/End If? How would I separate the actions?

    Please Login or Register  to view this content.
    Something like that maybe?

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Speed/Efficiency for If-Else Construct

    An Else is not a pre-requisite of an If construct, eg:

    Please Login or Register  to view this content.
    Sometimes you will see people code multiple lines on one line using a colon delimiter, eg:

    Please Login or Register  to view this content.
    The latter can be useful if condensing code into as few a lines as possible but generally speaking it's much harder to debug so is not adopted very often.

  6. #6
    Registered User
    Join Date
    03-31-2009
    Location
    Auburn Alabama
    MS-Off Ver
    Microsoft Office Excel 2007 (Windows)
    Posts
    99

    Re: Speed/Efficiency for If-Else Construct

    Awesome! Thanks again!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1