If and else, were should I put the more likely part?

Viewed 1853

I was wondering if there is a big performance difference in languages, whether you should put the more likely to be executed code in the if or in the else clause. Here is an example:

// x is a random number, or some key code from the user
if(!somespecific_keycode)
   do the general stuff
else
   do specific stuff

and the other solution

if(somespecific_keycode)
   do the specific stuff
else
   do general stuff
11 Answers
Related