Essential Go if, switch, goto  Edit on GitHub      File Issue

goto statements

A goto statement transfers control to the statement with the corresponding label within the same function.

Executing the goto statement must not cause any variables to come into scope that were not already in scope at the point of the goto.

func gotoIfOdd(n int) {
	if n%2 == 1 {
		goto isOdd
	fmt.Printf("%d is even\n", n)

	fmt.Printf("%d is odd\n", n)

func main() {
5 is odd
18 is even
  ↑ ↓ to navigate     ↵ to select     Esc to close