"if" vs. "switch"

Results 1 to 2 of 2

Thread: "if" vs. "switch"

  1. #1
    Join Date
    Dec 1969

    Default "if" vs. "switch"

    i remember reading a post on these boards, i think it was bill&#039;s, that claimed that an "if" decision structure executes faster than a "switch" decision structure.<BR><BR>QUESTIONS:<BR><BR>1. am i remembering correctly? if so...<BR><BR>2. is that always the case, regardless of the number of "elseif" statements in the decision structure, or is there a point at which perfomance decreases, and where a "switch" structure is more efficient?<BR><BR>3. is this true for asp.net as well, or just classic asp?

  2. #2
    Join Date
    Dec 1969

    Default RE:

    I thnk it&#039;s one of those &#039;depends on&#039; issues - A switch is usually more readable, which fits with my current policies of readable code winning the battle because of the general affordability of processing power. it also depends which way up you put your switch. this is acceptable :<BR><BR>switch(true) {<BR> case something==somethingelse&&something=blah: functioncall();<BR> case something==somethingelse2&&something2=blah: functioncall2();<BR> case something==somethingelse3&&something3=blah: functioncall3();<BR> case something==somethingelse4&&something4=blah: functioncall4();<BR>}<BR><BR>and it&#039;s, AFAIK less efficient. Bill has inside nowledge of the compilers so can give a more technical answer to thius, buit for now I stick by readablity....<BR><BR><BR><BR>j<BR>http://rtfm.atrax.co.uk/

Posting Permissions

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