If branch language

Sequential structure

Conditional statement: if syntax format: if conditional expression {}Copy the code
Package main import "FMT" func main() {num:=11 if num>10{FMT.Println(" >10 ")}}Copy the code

if... Else statementsCopy the code
Package main import "FMT" func main() {score:=0 FMT.Scanf("%d",&score) if score>=60 {FMT.Println(" score ")} else{score:=0 FMT. Println(" fail ")}}Copy the code

Note: {must be on the same line as the condition, else and} must be on the same line, if and else must execute one of them

Package main import "FMT" func main() {sex:="dasfa" if sex==" male "{fmt.println (" male ")}else{if sex==" female "{ Println(" is female ")}else {Println(" is not certain ")}}}else ifCopy the code

If num:=4; Else if(num<0){FMT.Println(" FMT.Println ")}else if(num<0){FMT.Println(" FMT.Println ")}Copy the code

Choose structure

Variable name {Case value 1: branch 1 Case value 2: branch 2 Case value 3: branch 3..... Default: last branch}Copy the code
Package main import "FMT" func main() {num:=3 switch num {case 1: FMT.Println(" FMT ") case 2: Println(" 四 区 ") case 4: Println(" 四 区 ")}}Copy the code

Println(" score ") if (score>=0 and score<60) if (score>=0 and score<70) Println("中 ") case score<80: Println("中 ") case score>=80&&score<90: Println {case "A","E","I","O","U": FMT.Println(" vowel ") case "M","N": FMT.Println("M or N") default: FMT.Println(" other ")Copy the code