title: non-name on left side of :=
body: <p>I am practicing / experimenting a bit with synchronisation mechanics in <code>go</code>.</p>
  
  <p>Why does the last <code>for</code> iteration fail to assign the values held by the buffered channel <code>valchan</code> into <code>mysl</code> slice?</p>
  
  <p>The error is </p>
  
  <blockquote>
    <p>./myprog.go:28:7: non-name mysl[i] on left side of :=</p>
  </blockquote>
  
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
      "sync"
  )
  
  const NUM_ROUTINES = 2
  
  func sendValue(c chan string) {
      c &lt;- "HelloWorld"
  }
  
  func main() {
      valchan := make(chan string, NUM_ROUTINES)
      var wg sync.WaitGroup
      wg.Add(NUM_ROUTINES)
  
      for i := 0; i &lt; NUM_ROUTINES; i++ {
          go func() {
              sendValue(valchan)
              wg.Done()
          }()
      }
      wg.Wait()
  
      mysl := make([]string, 2, 2)
      for i := 0; i &lt; NUM_ROUTINES; i++ {
          mysl[i] := &lt;-valchan
      }
  }
  </code></pre>