Order of output

Report a typo

Below is a Go program that uses a select statement to write to, read from, or default on the dataChan channel. Analyze the code and mark the correct order of the output lines produced by the fmt.Println() statements.

package main

import "fmt"

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

    for i := 0; i < 3; i++ {
        select {
        case dataChan <- 1:
            fmt.Println("write")
        case <-dataChan:
            fmt.Println("read")
        default:
            fmt.Println("default")
            break
        }
    }
}
Choose one option for each row
writereaddefault
1
2
3
___

Create a free account to access the full topic