Avatar ·

How to iterate over a range of integers from A to B in Go without creating a slice?

Hi everyone! I just started learning Go after Python and encountered an unexpected problem. In Python, I'm used to writing `for i in range(10, 20)` to simply iterate over numbers from 10 to 19. In Go, I expected to see something similar, but as far as I understand, `range` in Go only works with slices, arrays, strings, maps, and channels. I need to perform a simple task: print numbers from 1 to 100. I tried writing this: ```go for i := range 100 { fmt.Println(i) } ``` But it didn't work — the compiler complains that `range` requires an iterator. Then I tried doing this: ```go for i := 0; i < 100; i++ { fmt.Println(i) } ``` This works, but it seems very verbose compared to Python. So it turns out that Go doesn't have a built-in way to simply iterate