Go version
go1.24-ff2376dbe3
Output of go env in your module/workspace:
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/mneverov/.cache/go-build'
GODEBUG=''
GOENV='/home/mneverov/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/home/mneverov/tmp/go-build1984094783=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/mneverov/go/pkg/mod'
GOOS='linux'
GOPATH='/home/mneverov/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/mneverov/go/src/github.com/golang/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/mneverov/.config/go/telemetry'
GOTMPDIR='/home/mneverov/tmp'
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/mneverov/go/src/github.com/golang/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.24-ff2376dbe3 Sat Nov 16 08:22:18 2024 +0000'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
https://go.dev/play/p/Tt15KxMoRpO
func main() {
for k := range 4 {
switch k {
case 0:
continue
case 2:
break
default:
fmt.Printf("inside switch %d; ", k)
}
fmt.Printf("outside switch %d\n", k)
}
}
What did you see happen?
continue statement works for the loop i.e. on the first iteration (k=0) nothing will be printed.
break statement works for the switch, i.e. when k=2 outside switch 2 will be printed.
What did you expect to see?
Both continue and break work for either switch statement or loop statement.
I don't see a value in breaking a switch statement and would prefer both break and continue operating on the first loop switch statement belongs to.
Go version
go1.24-ff2376dbe3
Output of
go envin your module/workspace:What did you do?
https://go.dev/play/p/Tt15KxMoRpO
What did you see happen?
continuestatement works for the loop i.e. on the first iteration (k=0) nothing will be printed.breakstatement works for the switch, i.e. when k=2outside switch 2will be printed.What did you expect to see?
Both
continueandbreakwork for eitherswitchstatement orloopstatement.I don't see a value in
breaking a switch statement and would prefer bothbreakandcontinueoperating on the first loopswitchstatement belongs to.