This commit is contained in:
2024-08-01 23:40:06 +08:00
commit 1adca2ffe6
17 changed files with 469 additions and 0 deletions

45
main/defers.go Normal file
View File

@@ -0,0 +1,45 @@
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)
}
}