diff --git a/Switch.md b/Switch.md index a3e4dac9..50cf86bd 100644 --- a/Switch.md +++ b/Switch.md @@ -197,4 +197,27 @@ func do(v interface{}) string { do(21) == "42" do("bitrab") == "rabbit" do(3.142) == "unknown" -``` \ No newline at end of file +``` + +## Noop case + +Sometimes it useful to have cases that require no action. This can look confusing, because it can appear that both the noop case and the subsequent case have the same action, but isn't so. + +```go +func pluralEnding(n int) string { + ending := "" + + switch n { + case 1: + default: + ending = "s" + } + + return ending +} + +fmt.Sprintf("foo%s\n", pluralEnding(1)) == "foo" +fmt.Sprintf("bar%s\n", pluralEnding(2)) == "bars" + +``` + \ No newline at end of file