Sobes.tech
Junior — Senior

How do goroutines handle the loop variable during capture

livecode

Task condition

What will be the output of the following program?

func main() {
 wg := sync.WaitGroup{}

 for i := 0; i < 10; i++ {
  wg.Add(1)
  go func() {
   fmt.Println(i)
   wg.Done()
  }()
 }

 wg.Wait()
}