In Go, switch es are much more flexible than in C (and C ++), since they can handle cases of Boolean expressions and replace large else stairs - if , it would seem, completely, especially by default switch {...} blocks.
switch { case x < 5 && y > 2: //... case y == 1 || x > 2: //... default: }
Is there any advantage to using switch over else - if in Go? It seems that increased efficiency will be reduced by the flexibility of the switch . It is only up to the compiler to figure this out and see if it can make a jump table?
Is there any performance advantage when using switch over if and else ?
source share