He's still using If/Else when switch statements and expressions exist

>he's still using If/Else when switch statements and expressions exist

Attached: 1572152088505.gif (200x234, 2.85M)

#define IF 0
#define ELSE 1
switch (condition) {
case IF:
"fuck you\n";
break;
case ELSE:
":)\n";
break;
}

switch (2) {
// ???
}

switch is nice when you have some set of clearly defined things you're differentiating between. for example, let's say for some reason you have to translate numbers 1-12 to months of the year. I think switch would work nicely for this:

switch (num) {
case 1:
return "January"
case 2:
return "February"
...etc

but if you're doing something like trying to figure out where a num falls in a range, switch isn't good. for example let's say you want to describe someone's credit score as "bad", "decent", "good", "very good", or "excellent". if you're given a number like 628, how would you handle that with a switch statement?

i don't see any real use from using a switch case except in shell programming

>if you're given a number like 628, how would you handle that with a switch statement?
case 800...850:
printf("congratulations, enjoy your debt\n");
default:
printf("computer says no, git gud\n");
}

switch (num)
case < 100:
case < 200:
case < 300:


Exactly the same as you would with If?

switch (OP) {
case "Faggot"
return true;
}

cant use switch statements with runtime values

That only works if OP is located at the same memory location as string literal "Faggot"

ranges with switches are so ugly tho. i've also seen people do this way:

case 1:
case 2:
case 3:
doSomething()
case4:
case5:
case6:
doSomethingElse()

sry I shouldn't have said how but why. ranges with switch just doesn't seem to make sense to me from an aesthetic viewpoint. I do like it for situations with singular/distinct things tho

no default case required here lulz

You're holding it wrong

What hath science wrought?

You can switch on a runtime value, you just can't use them as a case

>he thinks switch statements map to jump tables
1980 called they want their compiler back

Switch cases in C/C++ are just labels, so you can do whatever you want. Turn a while loop into a do-while loop at runtime? No problemo.

switch (run_as_do_while) {
case 0:
while (condition) {
case 1:
foo();
}
}

I only use ternary ? :

so I compare runtime values to eachother in a switch statement

>if/else
>switch
what's faster in assembly language?

The CIA wants you to think that switch is just if else if else, but when switch compiles it creates a lookup table which significantly improves performance.

Not always but at worst it's as slow as an if/else statement.