title: Goroutine and for loop
body: <p>All I want to do is to send one value to the channel and return from the <code>main()</code> function and exit the program right after I receive one value from the channel <code>ch</code>.</p>
  
  <p>But this keeps running forever:</p>
  
  <pre><code>ch := make(chan int)
  
  for {
      go func() {
          ch &lt;- 1
      }()
  }
  
  &lt;-ch
  </code></pre>
  
  <p>How do I return with this <code>for</code> loop after I receive one value from the channel?</p>
  
  <p>And why does this run forever?</p>
  
  <p>Go playground link is here</p>
  
  <p><a href="http://play.golang.org/p/EvmT6Pw96Y" rel="nofollow">http://play.golang.org/p/EvmT6Pw96Y</a></p>