funcgrade(score int)string{
g :=""switch{case score <60:
g ="F"case score <80:
g ="C"case score <90:
g ="B"case score <=100:
g ="A"case score <0|| score >100://panic中断程序运行panic(fmt.Sprintf("Wrong score: %d", score))}return g
}
3.for
for的条件里面不需要括号
for的条件可以省略初始条件,结束条件,递增表达式
funcconvertToBin(n int)string{
result :=""for; n >0; n /=2{
lsb := n %2//strconv.Itoa() 转字符串
result = strconv.Itoa(lsb)+ result
}return result
}