Complete the code to receive a value from channel c1.
select {
case msg := <-[1]:
fmt.Println("Received", msg)
}The select statement waits for communication on channel c1. Receiving from c1 assigns the value to msg.
Complete the code to send the string "hello" to channel c2 inside the select.
select {
case [1] <- "hello":
fmt.Println("Sent hello")
}The send operation uses the channel name on the left side of the arrow. Here, c2 is the channel to send the string "hello".
Fix the error in the select statement to correctly receive from channel done.
select {
case <-[1]:
fmt.Println("Done signal received")
}The channel done is used to receive a signal without assigning it to a variable. The syntax <-done waits for a value from done.
Fill both blanks to receive from c1 and send "ok" to c2 inside the select.
select {
case msg := <-[1]:
fmt.Println("Received", msg)
case [2] <- "ok":
fmt.Println("Sent ok")
}The first case receives from c1 and assigns to msg. The second case sends the string "ok" to c2.
Fill all three blanks to receive from c1, send "done" to c2, and receive from done channel.
select {
case msg := <-[1]:
fmt.Println("Received", msg)
case [2] <- "done":
fmt.Println("Sent done")
case <-[3]:
fmt.Println("Done signal received")
}The first case receives from c1. The second sends "done" to c2. The third waits for a signal from done.