mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
Inserted work around for 'fallthrough' only being allowed as the last non-empty statement of a 'case' or 'default' clause
parent
77163493bc
commit
eda917fd38
15
Switch.md
15
Switch.md
@ -134,7 +134,22 @@ default:
|
||||
error()
|
||||
}
|
||||
```
|
||||
However, you can work around this by using a 'labeled' `fallthrough`:
|
||||
|
||||
```
|
||||
switch {
|
||||
case f():
|
||||
if g() {
|
||||
goto nextCase // Works now!
|
||||
}
|
||||
h()
|
||||
break
|
||||
nextCase:
|
||||
fallthrough
|
||||
default:
|
||||
error()
|
||||
}
|
||||
```
|
||||
## Multiple cases
|
||||
|
||||
If you want to use multiple values in the same case, use a comma-separated list.
|
||||
|
Loading…
x
Reference in New Issue
Block a user