This question already has an answer here:
- Short variable declaration and “variable declared and not used” error 2 answers
- Why does golang compiler think the variable is declared but not used? 1 answer
- Go compiler says “declared and not used” but they are being used 2 answers
- using := gives unused error but using = don't in Go 3 answers
- “declared and not used” Error 2 answers
Take this incredibly simple example. which shows variable assignment in and out of a block.
On compilation this results in: u declared and not used
var u string
{
u, err := url.Parse("http://bing.com/search?q=dotnet")
if err != nil {
log.Fatal(err)
}
}
log.Debug(u)
This simulates a logic block during which we might assess several things and set a var to the value we like depending on logic evaluation. How is this possible?
</div>