DEV Community

Discussion on: I've never become overly convinced that switch statements are that much cleaner than `if else if else if else if else`

Collapse
 
johnfound profile image
johnfound • Edited

It depends on the language syntax where switch is used.

For example, the "case" operator in Pascal does not fall-through (which is a serious problem in C-kind of languages).

In addition, the switch can be internally implemented in different way than a chain of ifs. For example with hash table, which can be much faster in the cases when you want to compare big amount of strings.