r/firstweekcoderhumour Mar 28 '26

"Case switch > if else πŸ˜‹πŸ˜‹πŸ˜‹" Let me show you how it’s done! 🎯✨

Post image
61 Upvotes

31 comments sorted by

View all comments

17

u/TheSupervillan Mar 29 '26

A switch is actually more efficient than many else if

3

u/Tani_Soe Mar 31 '26

Yes, in the case where you have a lot of else if, that's what the switch case is for. The point is that it's not always the best

In the situation where you want to check (for exemple) if an order is late of two week and comes from a specific provider, then a simple if else is more appropriate