Quantcast
Channel: Golang mixed assignment and declaration - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Golang mixed assignment and declaration

$
0
0

I started working with go for a few weeks, and (once again) I stumbled across something that seems odd for me:

// Not workinga := 1{    a, b := 2, 3}// Worksa := 1a, b := 2, 3

playground

I want to assign two variables simultaneously.One is already declared, in a superior scope, the other one is not.

It does not work: the compiler tries to redeclare the former variable.However, it works fine if this variable is declared in the same scope.

Why is that?


Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>