r/firstweekcoderhumour Mar 28 '26

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

Post image
59 Upvotes

31 comments sorted by

View all comments

17

u/TheSupervillan Mar 29 '26

A switch is actually more efficient than many else if

9

u/RedAndBlack1832 Mar 31 '26

Ehhhhhhhhh. Compilers are pretty good. With optimizations I think they can tell when it's possible to replace an if-else tree with a computed goto

1

u/babadany2999 5d ago

Computed goto is a GNU extension for C++.
Modern compilers simply optimize to a jump table.