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") } }
本文出自 “欺壹世De博客” 博客,请务必保留此出处http://qiyishi.blog.51cto.com/5731577/1894900
原文地址:http://qiyishi.blog.51cto.com/5731577/1894900