No way, it only works in the same block :

https://golang.org/ref/spec#Short_variable_declarations

 the for statement creates a new block . 

Le samedi 12 novembre 2016 03:49:35 UTC+1, so.q...@gmail.com a écrit :
>
>
> 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.

Reply via email to