Skip to content

Instantly share code, notes, and snippets.

@tomtsang
Created February 7, 2018 07:11
Show Gist options
  • Save tomtsang/fb44721d0d3b9426bbc94f6b86624cc6 to your computer and use it in GitHub Desktop.
Save tomtsang/fb44721d0d3b9426bbc94f6b86624cc6 to your computer and use it in GitHub Desktop.
golang-for-pattern1
// for 初始化语句; 条件语句; 修饰语句 {}
for i := 0; i < 5; i++ {
fmt.Printf("This is the %d iteration\n", i)
}
/*
初始化语句
for 条件语句 {
修饰语句
fmt.Printf("The variable i is now: %d\n", i)
}
*/
var i int = 5
for i >= 0 {
i = i - 1
fmt.Printf("The variable i is now: %d\n", i)
}
// 这些循环的本质就是无限循环。
// 条件语句是可以被省略的,如 i:=0; ; i++ 或 for { } 或 for ;; { }(;; 会在使用 gofmt 时被移除):
// 最后一个形式也可以被改写为 for true { },但一般情况下都会直接写 for { }
for { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment