title: Why does my concurrent function exit prematurely in Go?
body: <p>I am looking through Go Bootcamp and am reading the Go Concurrency chapter right now. I have never used concurrency before in programming and don't understand the output of this program:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "time"
  )
  
  func say(s string) {
      for i := 0; i &lt; 2; i++ {
          time.Sleep(100 * time.Millisecond)
          fmt.Println(s)
      }
  }
  
  func main() {
      go say("world")
      say("hello")
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>hello
  world
  hello
  
  Program exited.
  </code></pre>
  
  <p>Can someone explain why "world" is not printed twice like "hello"? And maybe elucidate the idea of using concurrency? </p>
  
  <p>Note, Go Playground link <a href="http://play.golang.org/p/9JvbtSuv5o" rel="nofollow">here</a>. </p>