That's true, although with todays computers the difference between if and switch is quite negligible, especially for small cases. Profiling to make a comparison between the two methods show that making an if-elseif-else block with 50 cases vs a switch block with 50 cases saves about 0.1ms. It's faster but this is often a micro-optimization, it's better to focus optimizations where it's actually needed.
I usually use switch when I have 4 or more cases as it becomes easier to manage or when I involve cpu-heavy operations in the cases, otherwise I use if-blocks. I find <=3 cased switch blocks bulky and makes the code hard to read. :)
Kakburk
Dave joined
Hello! I’m Dave, a pale and hairy person from Sweden who spend alot of my free time creating game assets, games and other types of softwares as a hobby. crumblingsoftware.net is the place I primarily use to showcase what I’m working on.