As he told you it depends on the data runs to the condition. If for exampe statistically there is more of 1's then 0 then the switch loop is faster, because:
1.) case is isolated 2.) You can reorder the case-statement according to the occurrent of the conditions On Nov 21, 2:59 pm, shiva <shivanand.kadwad...@gmail.com> wrote: > how it going to make difference in following case > ------------------------------------------ > i=0; > switch(i) > { > case 1: //some operation > case 0:// some operation} > > ------------------------------------------ > i=0; > if(i==1) > { > //some operation;} > > else if (i==0) > { > //Some operation} > > ------------------------------------------ > even compiler implement jump table like below > > key address > 1 xxxxx > 0 yyyyy > > Then two condition (worst case) need to be checked which is same as if > else if > > Please correct me if i am wrong > > On Nov 21, 6:35 pm, "MOHIT ...." <mohit...@gmail.com> wrote: > > > for switch in the worst case compiler will generate if else chain .. else it > > uses binary decision tree or jump table for optimization at compile time . -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.