   which is better switch if-else or ?:
  i wonder which brings the minimum load on program.which works more spedy.assume that in a programming situation you can use one of themwhich will you chose why?? 
  I would choose if for readability, most compilers would optimise this anyway. ;  As GamerSg said, choose what you like best. Things like that mattered 20 years ago (ok, maybe 10 years). On todays machines you will never ever notice the difference. ;  but an if else staircase is calculating every if-else till it founds the true.on the other hand switch just calculates one thing and thentrys to find the equal from the cases.?: is just calculatýn one thing and expressin gets the value of another experssion ..there must be diffrence blaa bla bla... in brief i still want to get an answer ;  Actually a switch statement compiles to a series of nested if statements if I remember correctly. Either way you are doing the same amount of compares.Go with what makes sense to you. ;  It does not matter which one.   They are both doing the same amount of work...the both need to do the same amount of comparasons (as far as i can see looking at it now...I have not used switch in a long time).   For switch, you have a value to begin with and compare this with every case...in if else you have a value and compare it to every option you want...i dont see the difference.The code is compiled to be the same at machine level anyway.I personally use if's and dilike the switch statement.   [edited by - Mr Lane on February 11, 2004 10:45:56 AM];  A switch is not compiled to a bunch of if-elses; it''s compiled into a jump table. The trinary operator evaluates to nearly identical code with the if-else, except that it has a return value and thus can be used in expressions:x = (condition) ? y : z;  Speed is a negligible concern, as others have posted. Readability is far more important, so switch wins out for large numbers of cases.Note that some languages (eg Python) do not have a switch statement at all, since it is functionally redundant (it''s pure syntactic sugar). ;  What''s a jump-table and how does it differ from nested if-else?   --{You fight like a dairy farmer!} ;switch(x) {  case 0:    doZero();    break;  case 1:    doOne();break;  case 3:    doThree(); // fall through case  case 4:    doFour();    break;}  gets compiled into psuedo assembly like:0001 offset = x;0002 addr = 00040003 jump to (addr + offset*2)0004 doZero()0005 jump to 00130006 doOne()0007 jump to 00130008 no op0009 jump to 00130010 doThree()0011 no op0012 doFour()0013 ...  Of course I've simplified things...[Edit:  I added the fall-through case to make it a little more interesting...]   [edited by - rypyr on February 11, 2004 5:53:39 PM] [edited by - rypyr on February 11, 2004 5:54:38 PM];  Beware the naive assumption that a switch is always a jump table though...http://www.eventhelix.com/RealtimeMantra/Basics/CToAssemblyTranslation3.htm 