mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-09-12 06:41:33 +00:00
good good study, day day up!
This commit is contained in:
29
vendor/gopl.io/ch8/countdown1/countdown.go
generated
vendored
Normal file
29
vendor/gopl.io/ch8/countdown1/countdown.go
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// 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!")
|
||||
}
|
Reference in New Issue
Block a user