Complete the code to add a default case in the select statement.
select {
case msg := <-ch:
fmt.Println("Received:", msg)
[1]:
fmt.Println("No message received")
}The default case in a select runs if no other case is ready.
Complete the code to print a message when no channel is ready using the default case.
select {
case <-ch1:
fmt.Println("ch1 ready")
case <-ch2:
fmt.Println("ch2 ready")
[1]:
fmt.Println("No channels ready")
}The default keyword alone defines the default case in a select.
Fix the error in the select statement by completing the default case correctly.
select {
case msg := <-ch:
fmt.Println("Got message:", msg)
[1]:
fmt.Println("No message received")
}The default case in Go's select uses only the keyword default without 'case'.
Fill both blanks to create a select with two channel cases and a default case.
select {
case msg1 := <-ch1:
fmt.Println("ch1:", msg1)
case msg2 := <-ch2:
fmt.Println("ch2:", msg2)
[1]:
fmt.Println("[2]")
}The default case starts with default: and the print statement shows the message.
Fill all three blanks to write a select that reads from two channels and uses a default case with a message.
select {
case val1 := <-chan1:
fmt.Println("chan1 value:", [1])
case val2 := <-chan2:
fmt.Println("chan2 value:", [2])
[3]:
fmt.Println("No data received")
}Use the variables val1 and val2 to print channel values, and default for the default case.