This question already has an answer here:
I got some problems with Go, I did have used tag in tag = true
// project main.go
package main
import (
"fmt"
)
func main() {
var m, odd1, odd2, in1, in2 int
tag := false
fmt.Scan(&m)
for i := 0; i < m; i++ {
fmt.Scan(&in1, &in2)
odd1 += in1
odd2 += in2
if (in1+in2)&1 == 1 {
tag = true
}
}
if odd1&1 == 0 && odd2&1 == 0 {
fmt.Print("0")
return
}
if odd1&1 == 0 && odd2&1 == 1 || odd1&1 == 1 && odd2&1 == 0 {
fmt.Print("1")
return
}
fmt.Print("-1")
}
</div>
'Not used' can be understood as 'has no effect'. While you're assigning true
to tag
, this is not propagated to the outside nor has any effect on the result of the function.
If you'd use tag
in a condition or return it, then the compiler wouldn't complain anymore.
You aren't using tag. You're assigning to it again. Using would mean it's on the right hand side of something: if tag { or if tag && odd1 && 1 == testVal {
This is a Christopher Pfohl answer