package main import ( "errors" "fmt" ) func t() error { a := 10 b := 5 if b == 0 { return errors.New("除数不能为零") } else { res := a / b fmt.Println(res) return nil } } func main() { err := t() if err != nil { fmt.Println("自定义错误") //停止后面程序继续执行 panic(err) } fmt.Println("继续执行") var scores [5]int scores[0] = 10 scores[1] = 10 scores[2] = 30 scores[3] = 40 for i := 0; i < len(scores); i++ { fmt.Println(scores[i]) fmt.Scanln(&scores[i]) } //索引用key接收 value用于里面的值 for key, value := range scores { fmt.Println(key, value) } }