I have the following program.
package main
import (
"fmt"
)
func main() {
for i := 0; i < 2; i++ {
x := 77
fmt.Println(x)
}
}
When executed I got:
77
77
As we can see, the x := 77
has been execute 2 times. However, If I modify it slightly like this:
package main
import (
"fmt"
)
func main() {
a := 77
fmt.Println(a)
a := 77
fmt.Println(a)
}
I will get the error "no new variables on left side of :=
". Why this? Can anyone help to explain it please? Thanks in advance.