I am trying to learn Go, but when trying out a simple for loop, I found it difficult to get it working. This code does not compile if I define the variable a in the main function, it gives an error 'a declared but not used'. I don't understand when a variable must be declared and when it must not be. Thanks.
package main
import "fmt"
func main() {
for a:=0;a<4;a++ {
fmt.Printf("value of a is %d\n",a)
}
}
at the end. Adding it works as intended.