4 ms·
"switch true {...}" or "switch {...}"? really? So how would switch 3.141592654 { ... } affect the case-statements inside?
by zvrba 15y ago
"switch true {...}" or "switch {...}"? really? So how would
switch 3.141592654 { ... }
affect the case-statements inside?
- chrisjsmith 15y agoNo idea as I wouldn't do it :) (sorry - cop out that)
- supersillyus 15y agoWhen you say "switch <value>", it matches the "case" statements based on if the value after "case" is equal to <value>. So, if you say const P = 3.141 switch 3.141 { case P: fmt.Println("This prints") } When no value is specified after "switch", the value of "true" is implied, which is why you can do: switch { case a && b: .. case something(): }