Sobes.tech
Junior — Senior

Find and fix errors in the Go program

livecode

Task condition

In this fragment of Go code, there are errors that prevent the program from terminating correctly and may cause a panic. It is necessary to fix them so that the sequence of numbers from the channel is fully outputted and the program terminates without an infinite loop.

func main() {
  ch := make(chan int, 5)
  for i := 1; i <= 5; i++ {
    ch <- i
  }

  close(ch)

  for true {
    fmt.Println(<-ch)
  }
}