From 63e14fa99afd4b628c44f09e897eb8e8439b2b6a Mon Sep 17 00:00:00 2001 From: Atila Romero Date: Thu, 2 Aug 2018 16:21:07 -0300 Subject: [PATCH] Easier to understand fallthrough example --- Switch.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Switch.md b/Switch.md index 50cf86bd..39445a80 100644 --- a/Switch.md +++ b/Switch.md @@ -102,6 +102,29 @@ default: To fall through to a subsequent case, use the ` fallthrough ` keyword: +```go +v := 42 +switch v { +case 100: + fmt.Println(100) + fallthrough +case 42: + fmt.Println(42) + fallthrough +case 1: + fmt.Println(1) + fallthrough +default: + fmt.Println("default") +} +// Output: +// 42 +// 1 +// default +``` + +Another example: + ```go // Unpack 4 bytes into uint32 to repack into base 85 5-byte. var v uint32