Andrew's Digital Garden

Switch in Go

switch without a condition can be used to write an if/else chain.

Case statements can have multiple expressions separated by a comma.

switch motion { case "walk", "run": // Do something

Cases inside the switch also don't require a break, as it only runs the selected case. To fall through programtically, the fallthrough keyword can be used.

There's also a type switch (TODO)

[[go]]

Switch in Go