I'm developing in golang and I run the following for loop:
// Define Initial Value
i := 0
for {
// Get Random data based on iteration
data, i := GiveRandomData(i)
// Save to database
response, err := SaveToDatabase(data)
if err != nil { log.Fatal(err) }
fmt.Println(response)
}
However, when compiling this program, I get the following error:
.\main.go:26: i declared and not used
The Golang compiler doesn't seem to recognise that the i variable is given back to the function in the next loop. Inside this function, the I variable changes value.
What should I do to get rid of this compilation error or to let golang understand that this variable is NOT unused but used in the next iteration of this endless for loop?