Is there a way to iterate over a range of integers?

The idiomatic approach in Go is to write a for loop like this.

for i := 1; i <= 10; i++ {
    fmt.Println(i)
}

There’s definitely advantages in ranges and they’re used in many other languages, but a Go design principle is to only introduce an abstraction if the benefits significantly outweigh the costs (including the cost of making the language larger). Reasonable people disagree about the costs and benefits of ranges, but this answer is my attempt to describe what I think idiomatic Go is.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)