Forloop
Go has only one type of loop and that's the for
loop.
Python
- i = 1
- while i <= 10:
- print i
- i += 1
- # ...or...
- for i in range(1, 11):
- print i
Go
- package main
- import "fmt"
- func main() {
- i := 1
- for i <= 10 {
- fmt.Println(i)
- i += 1
- }
- // same thing more but more convenient
- for i := 1; i <= 10; i++ {
- fmt.Println(i)
- }
- }