Essential Go if, switch, goto  Suggest an edit

goto statements

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

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

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

printIsOdd(5)
printIsOdd(18)
5 is odd
18 is even

goto can't skip over variable declarations:

	goto end
	a := 3
	fmt.Printf("a: %d\n", a)
end:
# command-line-arguments
./main.go:8:7: goto end jumps over declaration of a at ./main.go:9:4

  ↑ ↓ to navigate     ↵ to select     Esc to close