Default branch

Report a typo

In what cases will the code in the default branch be executed?

package main

import "fmt"

func main() {
    chan1 := make(chan int, 1)
    chan2 := make(chan int, 1)

    defer close(chan1)
    defer close(chan2)

    for {
        select {
        case chan1 <- 1:
            fmt.Println("The data is written to the first channel.")
        case chan2 <- 2:
            fmt.Println("The data is written to the second channel.")
        default:
            fmt.Println("default")
            return
        }
    }
}
Select one or more options from the list
___

Create a free account to access the full topic