title: Returning Channels Golang
body: <p>I'm trying with Go channels and confused with below function example from go blog:</p>
  
  <pre><code>func gen(nums []int) &lt;-chan int {
      out := make(chan int)
      go func() {
          for _, n := range nums {
              out &lt;- n
          }
          close(out)
      }()
      fmt.Println("return statement is called ")
      return out
  }
  </code></pre>
  
  <p>Main :</p>
  
  <pre><code>func main() {
      c := make(chan int)
      c = gen([]int{2, 3, 4, 5})
  
      // Consume the output.
      // Print 2,3,4,5
      fmt.Println(&lt;-c)
      fmt.Println(&lt;-c)
      fmt.Println(&lt;-c)
      fmt.Println(&lt;-c)
  }
  </code></pre>
  
  <p>Complete Code: <a href="http://play.golang.org/p/Qh30wzo4m0" rel="nofollow noreferrer">http://play.golang.org/p/Qh30wzo4m0</a></p>
  
  <p>My Doubts:</p>
  
  <ol>
  <li><p>My understanding was, once <code>return</code> is called the function will be terminated and the channel inside that function has no more life. </p></li>
  <li><p>The <code>return</code> statement is called only once. But the content of the <code>out</code> channel is read many times. In this case what is the actual flow of execution?</p></li>
  </ol>
  
  <p>(I'm new to concurrent programming.)</p>