Skip to content

Instantly share code, notes, and snippets.

@haozibi
Last active April 15, 2019 06:11
Show Gist options
  • Save haozibi/12906f9c8cf5c894c1b14386f5c57c3c to your computer and use it in GitHub Desktop.
Save haozibi/12906f9c8cf5c894c1b14386f5c57c3c to your computer and use it in GitHub Desktop.
golang goto 测试
package main
import (
"fmt"
"sync/atomic"
)
var b = 1
func main() {
run2()
run()
}
func run2() {
retry:
fmt.Println("222")
if b != 1 {
goto retry
}
}
func run() {
var a int64 = 1
goto exit
exit:
fmt.Println("exit", a)
atomic.AddInt64(&a, 1)
if a == 10 {
return
}
goto exit
}
// output:
// 222
// exit 1
// exit 2
// exit 3
// exit 4
// exit 5
// exit 6
// exit 7
// exit 8
// exit 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment