gopl-zh.github.com/vendor/gopl.io/ch8/countdown1/countdown.go
github-actions[bot] ca571eb691 deploy: 06a1bdf735
2022-08-04 06:59:33 +00:00

30 lines
488 B
Go

// Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
// See page 244.
// Countdown implements the countdown for a rocket launch.
package main
import (
"fmt"
"time"
)
//!+
func main() {
fmt.Println("Commencing countdown.")
tick := time.Tick(1 * time.Second)
for countdown := 10; countdown > 0; countdown-- {
fmt.Println(countdown)
<-tick
}
launch()
}
//!-
func launch() {
fmt.Println("Lift off!")
}