golang的条件语句:
package main import ( "fmt" ) func main(){ age := 18 // if else if else 语句 if age == 18 { fmt.Println("your age is 18") }else if age > 18{ fmt.Println("your age is bigger than 18") }else { fmt.Println("your age is smaller than 18") } //swith 语句 匹配一个就退出 switch age { case 16: fmt.Println(your age is 16) case 18: fmt.Println(your age is 18) default: fmt.Println(your age is not 16 or 18) } //switch语句另一种写法 switch { case age < 18: fmt.Println(your age is smaller than 18) case age > 18: fmt.Println(your age is bigger than 18) default: fmt.Println(your age is not 16 or 18) } // for 循环 for i :=0;i <10;i++{ fmt.Println(i) } // for 循环另一种写法 i := 0 for ; i<10;i++{ fmt.Println(i) } //for 循环另一种写法 i := 0 for i < 10{ fmt.Println(i) i++ } // for 死循环 for { fmt.Println("1") } }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。