package main import "fmt" func main() { // 单分支 // 判断分数 及格还是不及格 var score int = 59 if score >= 60 { println("及格") } else { println("不及格") } score = 85 // 多分支 // 判断分数 优秀 良好 中等 及格 不及格 if score >= 90 { println("优秀") } else if score >= 80 { println("良好") } else if score >= 70 { println("中等") } else if score >= 60 { println("及格") } else { println("不及格") } // switch 多分支 进行重写 switch { case score >= 90: println("优秀") case score >= 80: println("良好") fallthrough case score >= 70: println("中等") case score >= 60: println("及格") fallthrough default: println("不及格") } // 练习题 // 身高1.8m以上, 25 ~ 35岁, 男 // 则恭喜你通过面试 否则 谢谢参与 p := Person{ height: 1.9, age: 30, gender: "male", } if p.Passed() { fmt.Println("congratulations! your successed") } else { fmt.Println("not passed") } } type Person struct { height float32 age uint gender string } // 身高1.8m以上, 25 ~ 35岁, 男 func (p *Person) Passed() bool { if p.height > 1.8 { if p.age > 25 && p.age <= 35 { if p.gender == "male" { return true } } } return false }