Hi all.

I'm studying about *if statement* and *comma ok construction* and I'm not 
sure why the piece of code (https://go.dev/play/p/ScFJsih6lwR) bellow does 
not work. The compiler says that: *x declared but not used*. However, *x* is 
used in the second *if statement *of the *main function*, as you can see.

It is worthy to notice that  *x* is just assigned (not declared) in the 
first *if *of the *main function*, because I declared it as follows: *var x 
int*  

func MyFunc() (int, bool) {
        return 1, true
}

func main() {
        var x int
        if x, ok := MyFunc(); !ok {
                fmt.Println("Err")
        }
        fmt.Println(x)
}

Thank you and best regards, 
Paulo.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5804dce1-afa5-4045-96b5-cf9418da1c92n%40googlegroups.com.

Reply via email to