Golang的跳转语句(GOTO)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main

import (
"fmt"
"time"
)

func main() {


STUDYHARD:
fmt.Println("开始努力奋斗!")
var i int = 0
for {
fmt.Printf("努力奋斗了%d小时\n", i)
time.Sleep(500 * time.Millisecond)
i++

if i > 10 {
//跳出当前循环
//break
fmt.Println("恭喜你获得了组织颁发的奖状!")
goto TRYAGIN
}
}

BONUS:
fmt.Println("循环外的世界")
fmt.Println("送你海景别野一套")
fmt.Println("送你满汉全席一套")
fmt.Println("送你我厂生产的女朋友一个")

TRYAGIN:
var answer string
fmt.Println("要不要再玩一次呢?Y/N")
fmt.Scan(&answer)
if answer == "N" {
goto GAMEOVER
} else if answer == "Y" {
goto STUDYHARD
}else if answer == "FUCKOFF"{
goto BONUS
}

GAMEOVER:
fmt.Println("GAME OVER")
}