Forloop

Go has only one type of loop and that's the for loop.

Python

  1. i = 1
  2. while i <= 10:
  3. print i
  4. i += 1
  5.  
  6. # ...or...
  7.  
  8. for i in range(1, 11):
  9. print i

Go

  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6. i := 1
  7. for i <= 10 {
  8. fmt.Println(i)
  9. i += 1
  10. }
  11.  
  12. // same thing more but more convenient
  13. for i := 1; i <= 10; i++ {
  14. fmt.Println(i)
  15. }
  16. }