Keyword

Go default keyword

Provides the fallback branch of a switch or a select. In select, default runs only when no communication case can proceed; without it, select waits. At most one default is allowed per statement. Example prints idle.

Formal Syntax & Structure

go syntaxgo
default:

Working Example

Example Snippetgo
package main
import "fmt"
func main() {  ch := make(chan int)  select {  case v := <-ch:    fmt.Println(v)  default:    fmt.Println("idle")  }}
Go Reference