3 ms·
In Golang, a missing switch expression is equivalent to the value `true`, so this shortens further to: switch { ... }
by majewsky 7y ago
In Golang, a missing switch expression is equivalent to the value `true`, so this shortens further to:
switch {
...
}
- krylon 7y agoBut in Go, case-values must be constants, right? This would make the trick from the referenced source code impossible, I think. (Whether or not that is a good or a bad thing is a question I am deliberately ignoring.)
- lsaferite 7y agoNot true. Go uses logic expressions in the case statements all the time. And as pointed out above, a switch defaults to checking against true. https://tour.golang.org/flowcontrol/11 https://tour.golang.org/flowcontrol/11