I think what is happening when you do the := is that the ok in there is getting shadowed (the for loop is creating a new block) and so the compiler see it as a new variable that is not being used.
Sent from my iPhone > On Nov 11, 2016, at 18:49, so.qu...@gmail.com wrote: > > > I thought it was possible to do partial assignment where, if one variable is > already declared and a new one is not. > https://stackoverflow.com/questions/39028645/golang-variable-assignment > > In the below example ok has been declared prior, but v has not. Trying to run > the below results in an error "undefined: v", but I thought this was possible? > https://play.golang.org/p/dlRpcFGsSM > > package main > > import ( > "fmt" > ) > > func Foo() (int,bool) { > return 1,false > } > > func main() { > ok := true > for ok { > v,ok = Foo() // v,ok := Foo(), doesn't work either > fmt.Println(v) > } > fmt.Println(ok) > } > > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.