This commit is contained in:
Mark McGranaghan 2012-09-20 20:32:58 -07:00
parent 67c7a30b0f
commit f94d7463aa

View File

@ -1,20 +1,17 @@
// `for` is Go's only looping construct. Below are two common
// forms.
package main // `for` is Go's only looping construct. Below are
// two common forms.
import "fmt"
func main() {
i := 1 // We initialize `i` with `1` and loop until it's 10.
for i <= 10 {
fmt.Println(i)
i = i + 1
}
for j := 1; j <= 10; j++ { // That type of loop is common. We can do it on one
fmt.Println(j) // line.
}
} // There are other forms of `for`; we'll see them
// later.
package main
import "fmt"
func main() {
i := 1 // We initialize `i` with `1` and loop until it's 10.
for i <= 10 {
fmt.Println(i)
i = i + 1
}
for j := 1; j <= 10; j++ { // This is a common idiom. We can do it on one line.
fmt.Println(j)
}
}
// There are other forms of `for`; we'll see them later.