golang的条件语句:
packagemain import( "fmt" ) funcmain(){ age:=18 //ifelseifelse语句 ifage==18{ fmt.Println("yourageis18") }elseifage>18{ fmt.Println("yourageisbiggerthan18") }else{ fmt.Println("yourageissmallerthan18") } //swith语句匹配一个就退出 switchage{ case16: fmt.Println(yourageis16) case18: fmt.Println(yourageis18) default: fmt.Println(yourageisnot16or18) } //switch语句另一种写法 switch{ caseage<18: fmt.Println(yourageissmallerthan18) caseage>18: fmt.Println(yourageisbiggerthan18) default: fmt.Println(yourageisnot16or18) } //for循环 fori:=0;i<10;i++{ fmt.Println(i) } //for循环另一种写法 i:=0 for;i<10;i++{ fmt.Println(i) } //for循环另一种写法 i:=0 fori<10{ fmt.Println(i) i++ } //for死循环 for{ fmt.Println("1") } }原文链接:https://www.f2er.com/go/188956.html