if

func main() {
const filename= "abc.txt"

/*
if 的条件里可以赋值;
if 的条件里的赋值的作用域就在这个if语句里
*/
if contents, err := ioutil.ReadFile(filename); err != nil {
fmt.Println("cannot print file contents:", err)
} else {
fmt.Printf("%s\n", contents)
}
}

switch

func grade(score int) string{
var g = ""
switch {
case score < 0 || score > 100:
panic(fmt.Sprintf("wrong score : %d",score))
case score < 60 :
g = "F"
case score < 70:
g = "D"
case score < 80:
g = "C"
case score < 90:
g = "B"
case score < 100:
g = "A"
}
return g
}


●switch后可以没有表达式