title: "Select" statement inside of goroutine with for loop
body: <p>Could somebody please explain, why if goroutine has endless <code>for</code> loop and <code>select</code> inside of the loop, a code in the loop is run only one time?</p>
  
  <pre><code>package main
  
  import (
      "time"
  )
  
  func f1(quit chan bool){
      go func() {
          for {
              println("f1 is working...")
              time.Sleep(1 * time.Second)
  
              select{
              case &lt;-quit:
              println("stopping f1")
              break
              }
          }   
      }()
  }
  
  func main() {
      quit := make(chan bool)
      f1(quit)
      time.Sleep(4 * time.Second)
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>f1 is working...
  Program exited.
  </code></pre>
  
  <p>But if "select" is commented out:</p>
  
  <pre><code>package main
  
  import (
      "time"
  )
  
  func f1(quit chan bool){
      go func() {
          for {
              println("f1 is working...")
              time.Sleep(1 * time.Second)
  
              //select{
              //case &lt;-quit:
              //println("stopping f1")
              //break
              //}
          }   
      }()
  }
  
  func main() {
      quit := make(chan bool)
      f1(quit)
      time.Sleep(4 * time.Second)
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>f1 is working...
  f1 is working...
  f1 is working...
  f1 is working...
  f1 is working...
  </code></pre>
  
  <p><a href="https://play.golang.org/p/MxKy2XqQlt8" rel="noreferrer">https://play.golang.org/p/MxKy2XqQlt8</a></p>