What is the purpose of the range keyword when working with channels?

  • It is used to specify the channel's data type.
  • It iterates over the values received from a channel.
  • It closes the channel automatically.
  • It sets a timeout for channel operations.
The range keyword in Go is used when working with channels to iterate over the values received from the channel. It simplifies the process of receiving data from a channel in a loop until the channel is closed. It ensures that the loop continues until the channel is closed, preventing Goroutines from waiting indefinitely for more data.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *