初始化
This commit is contained in:
3
01_basics/04_control_flow/01_conditionals/go.mod
Normal file
3
01_basics/04_control_flow/01_conditionals/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module conditionals
|
||||
|
||||
go 1.23.5
|
25
01_basics/04_control_flow/01_conditionals/main.go
Normal file
25
01_basics/04_control_flow/01_conditionals/main.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
score := 85
|
||||
|
||||
// if-else条件语句
|
||||
if score >= 90 {
|
||||
fmt.Println("优秀")
|
||||
} else if score >= 80 {
|
||||
fmt.Println("良好")
|
||||
} else if score >= 60 {
|
||||
fmt.Println("及格")
|
||||
} else {
|
||||
fmt.Println("不及格")
|
||||
}
|
||||
|
||||
// 带初始化的if语句
|
||||
if num := 9; num%2 == 0 {
|
||||
fmt.Printf("%d是偶数\n", num)
|
||||
} else {
|
||||
fmt.Printf("%d是奇数\n", num)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user