package main

import (
	"fmt"
	"time"
)

func main() {
	ticker := time.NewTicker(500 * time.Millisecond)
	defer ticker.Stop()

	done := time.After(3 * time.Second)

	// section: main
loop:
	for {
		select {
		case <-ticker.C:
			fmt.Println("tick")
		case <-done:
			fmt.Println("done")
			break loop // breaks out of the for loop using the label
		}
	}
	// section: main

	fmt.Println("exiting")
}

/*
// section: output
$ go run main.go
tick
tick
tick
tick
tick
tick
done
exiting
// section: output
*/
