如何在不使用迭代器的情况下在Golang中循环?

I know this works.

for i :=range []int{1, 2, 3....} {
    fmt.Println(i)
}

But If I want to do something like:

for i :=range []int{1, 2, 3....} {
    code = GenNewCode()
    Insert(code)
}

I get an error that i was not used. Is there a way I can do it without getting the above error? (Pardon me if this is a silly question, I am just learning Golang a bit.)

You can ignore such things by using the blank identifier: _

for _ := range []int{1, 2, 3} {
    code = GenNewCode()
    Insert(code)
}

Or one can use (via JimB's comment)

for range []int{1, 2, 3}{
code = GenNewCode()
    Insert(code)
}