Switch#
A switch statement handles conditional branching.
Blank Switch#
A blank switch is a switch statement without an expression. It is equivalent to switch true. It is useful for writing long if-else-if chains more clearly.
eg.
switch {
case x < 0:
return -x
case x == 0:
return 0
default:
return x
}Initialization Statement#
A switch statement can include a short initialization statement before the expression. The variables declared in this statement are only in scope within the switch block.
eg.
switch x := f(); {
case x < 0:
return -x
default:
return x
}