go的if语句可以这么用:
import (
"fmt"
"io/ioutil"
)
const filename = "abc.txt"
if contents, err := ioutil.ReadFile(filename); err != nil { // contents作用域仅在该block下
fmt.Println(err)
} else {
fmt.Printf("%s\n", contents)
}
go的switch语句可以这么用:
g := ""
switch { // 不需要写break,如果需要继续放下执行,需要使用fallthrough
case score < 0 || score > 100:
panic(fmt.Sprintf("Wrong score: %d", score))
case score < 60:
g = "F"
case score < 80:
g = "C"
case score < 90:
g = "B"
case score <= 100:
g = "A"
}