title: Channel communication behaviour with select statement in goroutines
body: <p>This is a modified version of the one provided by <a href="https://tour.golang.org/concurrency/5" rel="nofollow noreferrer">&quot;A Tour of Go&quot;</a>.</p>
  <pre><code>package main
  
  import &quot;fmt&quot;
  
  func fibonacci(c, quit chan int) {
      x, y := 0, 1
      for {
          select {
          case c &lt;- x:
              x, y = y, x+y
              fmt.Println(&quot;GEN&quot;, x)
          case &lt;-quit:
              fmt.Println(&quot;quit&quot;)
              return
          }
      }
  }
  
  func main() {
      c := make(chan int)
      quit := make(chan int)
      go func() {
          for i := 0; i &lt; 10; i++ {
              fmt.Println(&quot;DISP&quot;, &lt;-c)
          }
          quit &lt;- 0
      }()
      fibonacci(c, quit)
  }
  </code></pre>
  <p>Here is the output for the above code:</p>
  <pre><code>DISP 0
  GEN 1
  GEN 1
  DISP 1
  DISP 1
  GEN 2
  GEN 3
  DISP 2
  DISP 3
  GEN 5
  GEN 8
  DISP 5
  DISP 8
  GEN 13
  GEN 21
  DISP 13
  DISP 21
  GEN 34
  GEN 55
  DISP 34
  quit
  </code></pre>
  <p>I don't understand the behaviour of the code. Why are 2 Fibonacci numbers generated before displaying both of them? Does this depend on the execution environment?</p>