mirror of
https://github.com/golang/go.git
synced 2024-11-22 05:40:42 +00:00
Easier to understand fallthrough example
parent
01d386c23f
commit
63e14fa99a
23
Switch.md
23
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
|
||||
|
Loading…
Reference in New Issue
Block a user