I am trying to figure out how the label gap works.
I expect the following program to print "In if statement" forever. This is because the statement break herereturns the execution of the code to the beginning of the loop, which then must be executed again and again.
However, this code is executed only once. What am I missing here?
package main
import "fmt"
func main() {
here:
for {
fmt.Println("In if statement")
break here
}
fmt.Println("At the bottom")
}
Execution Result:
In if statement
At the bottom
Program exited.
http://play.golang.org/p/y9kH1YZezJ
source
share