RosettaCodeData/Task/Scope-Function-names-and-labels/Go/scope-function-names-and-labels-3.go
2023-07-01 13:44:08 -04:00

29 lines
589 B
Go

package main
import "fmt"
func main() {
// labels loop and y both in scope of main
loop:
for false {
continue loop
}
goto y
y:
y := 0 // variable namespace is separate from label namespace
func() {
// goto loop ...loop not visible from this literal
// label y in outer scope not visible so it's okay to define a label y
// here too.
y:
for {
break y
}
y++ // regular lexical scoping applies to variables.
}()
fmt.Println(y)
}
// end: // labels not allowed outside function blocks