I am new to Go. And this "declared but not used" error is really something. I mean, annoying.
Here is my code:
func addBorder(a []string) []string {
var result []string
wall := ""
for i := range a {
newElement := "*" + a[i] + "*"
fmt.Println(newElement)
result = append(result, newElement)
}
for i := range a[0] {
wall += "*"
}
result = append([]string{wall}, result...)
return result
}
The problem is the second for loop. It keeps saying that "i declared but not used" all the time and no idea how to deal with it. I don't really need it besides using it to iterate. Adding i += 0
solved it but that is definitely not a good way to deal with this problem. Can anyone enlighten me? Thanks.