Switch-case VS if-else

When to use Switch-case statements over if-else and vice-versa?
if i'm simply testing the value of integer(or enum) i use switch, else (ho ho...) i use if..else.

agree witch Mutexe and also - when you have to use more than 3 IFs, rather use SWITCH
Okay thanks.
Not really.
You use switch(case) and if(else) whenever you want, except that:
switch(case) CAN'T take non-constant arguments. What does it mean?
It means, that your variable value must be known at compile-time. if-else doesn't require that.
Check this:



PS. Oh, and switch-else can handle only integral types, if I'm not wrong(char is integral type). So you can't check for const char* , since string isn't integral.

More info:
Last edited on
Topic archived. No new replies allowed.