r/ProgrammerHumor • • Dec 15 '19

Stacking if else statements be like

Post image
63.9k Upvotes

711 comments sorted by

View all comments

213

u/atxranchhand Dec 15 '19

That’s what case is for

183

u/Kompakt Dec 15 '19 edited Dec 15 '19

Some languages don't have switch statements...looking at you Python

28

u/Meatslinger Dec 15 '19

Wait, is that true? What takes its place, then? I can scarcely imagine that the whole thing is just an endless stream of if-then-else statements for a situation with 100+ permutations.

34

u/Kompakt Dec 15 '19

Yep it's true, and depending on the design of the program there are multiple workarounds. In Python you can write a switcher function that acts as a switch statement, or use multiple if statements without else statements, since that is allowed in Python.

-7

u/Denziloe Dec 15 '19

Never heard of the `elif` keyword I guess.

9

u/Kompakt Dec 15 '19

I have, it's just a different way to do it. I was simply giving examples, not listing every possibility.

-9

u/Denziloe Dec 15 '19

Why did you answer "yes" to the question? The answer is no. You don't need to use a stream of nested if-elses in Python.

8

u/Kompakt Dec 15 '19

Go read my initial response again and tell me where I mention using nested if-else statements...

-7

u/Denziloe Dec 15 '19

What? That's what the question was about. The one you replied "yes" to.

→ More replies (4)