Language Go
(Implementation of the channel type.)
Date: | 11/10/10 |
Author: | Marcos Vazquez |
URL: | n/a |
Comments: | 0 |
Info: | http://golang.org |
Score: | (1.66 in 50 votes) |
/* The 99 Bottles of Beer in the Go Proramming Language * * Marcos Vazquez * mvazquez[at]tamps.cinvestav[dot]mx * November 10, 2010 * */ package main import "fmt" var bottlesOfBeer int = 99; func takeOneBeer(ch chan bool) { bottlesOfBeer--; go singTheSong(ch) } func singTheSong(ch chan bool) { if bottlesOfBeer > 1 { fmt.Printf("%d bottles of beer on the wall, %d bottles of beer.\n", bottlesOfBeer, bottlesOfBeer) fmt.Println("Take one down and pass it around, 97 bottles of beer on the wall.\n") go takeOneBeer(ch) } else if bottlesOfBeer == 1 { fmt.Println("1 bottle of beer on the wall, 1 bottle of beer.") fmt.Println("Take one down and pass it around, no more bottles of beer on the wall.\n") go takeOneBeer(ch) } else { fmt.Println("No more bottles of beer on the wall, no more bottles of beer.") fmt.Println("Go to the store and buy some more, 99 bottles of beer on the wall.") ch <- true } } func main() { ch := make(chan bool) go singTheSong(ch) <- ch }
Download Source | Write Comment
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments