标签:输入 span printf break 流程 bsp adf pre \n
if-else:
package main import ( "io/ioutil" "fmt" ) func main(){ const filename="abc.txt" //读文件 content,err :=ioutil.ReadFile(filename) if err !=nil{ fmt.Println(err) }else{ fmt.Printf("%s\n",content) } //if也支持如下语法 if content,err :=ioutil.ReadFile(filename);err !=nil{ fmt.Println(err) }else{ fmt.Printf("%s\n",content) } }
switch:
package main import "fmt" //传入成绩,返回评分等级 func grade(score int) string { //定义字符串 g := "" //go为switch每一句都加了break switch { case score < 0 || score > 100: g = "输入错误" case score < 60: g = "不及格" case score < 80: g = "良" case score < 90: g = "优" case score <= 100: g = "GOOD" } //default: "hahah" return g } func main(){ fmt.Println( grade(0), grade(61), grade(75), grade(86), grade(86), grade(101), ) }
标签:输入 span printf break 流程 bsp adf pre \n
原文地址:https://www.cnblogs.com/tjp40922/p/10802424.html