mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +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:
|
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
|
```go
|
||||||
// Unpack 4 bytes into uint32 to repack into base 85 5-byte.
|
// Unpack 4 bytes into uint32 to repack into base 85 5-byte.
|
||||||
var v uint32
|
var v uint32
|
||||||
|
Loading…
x
Reference in New Issue
Block a user