From 5b7c5e7f3f451d8c179a1e3d59f6cf4e7cd3c846 Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Sat, 22 Sep 2012 14:17:22 -0400 Subject: [PATCH] formatting --- 008-for.go | 30 +++++++++++++++--------------- 009-if-else.go | 4 ++-- 039-synchronization.go | 10 +++++----- xxx-line-filter.go | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/008-for.go b/008-for.go index dc4bd38..fee9aeb 100644 --- a/008-for.go +++ b/008-for.go @@ -1,23 +1,23 @@ -package main // `for` is Go's only looping construct. Below are - // two common forms. +package main // `for` is Go's only looping construct. Below are + // two common forms. import "fmt" func main() { - i := 1 // We initialize `i` with `1` and loop until it's 10. - for i <= 3 { - fmt.Print(i) - i = i + 1 - } + i := 1 // Initialize `i` with `1` and loop until it's 10. + for i <= 3 { + fmt.Print(i) + i = i + 1 + } - for j := 1; j <= 3; j++ { // That type of loop is common. We can do it on one - fmt.Print(j) // line. - } - - for { // `for` without a condition will loop until you - fmt.Println() // `return`. - return + for j := 1; j <= 3; j++ { // That type of loop is common. We can do it on one + fmt.Print(j) // line. } -} // We'll see other `for` forms latter. + + for { // `for` without a condition will loop until you + fmt.Println() // `return`. + return + } +} // We'll see other `for` forms latter. /* $ go run for.go diff --git a/009-if-else.go b/009-if-else.go index 4b48531..a5954f7 100644 --- a/009-if-else.go +++ b/009-if-else.go @@ -4,8 +4,8 @@ import "fmt" func main() { fmt.Print("7 is ") - if 7 % 2 == 0 { // If/else is straightford. Note that there are no - fmt.Println("even") // enclosing parenthesis around the condition. + if 7 % 2 == 0 { // If/else is straight-forward. Note that there are no + fmt.Println("even") // enclosing parentheses around the condition. } else { // Also, there is no ternary operator (`?`) in Go. fmt.Println("odd") } diff --git a/039-synchronization.go b/039-synchronization.go index acbe6d8..690fad0 100644 --- a/039-synchronization.go +++ b/039-synchronization.go @@ -1,20 +1,20 @@ package main // We can use channels to synchronize execution - // accross goroutings. Here's an example of waiting -import "fmt" // for another gorouting to finish. + // accross goroutines. Here's an example of waiting +import "fmt" // for another goroutine to finish. import "time" func worker(done chan<- bool) { // The `done` channel will be used for fmt.Print("Working...") // synchronization. time.Sleep(time.Second) fmt.Println(" done") - done <- true // Send a value to notify that the work is done. + done <- true // Send a value to notify that the work is done. } func main() { - done := make(chan bool, 1) // Start a worker goroutine, give it the channel to + done := make(chan bool, 1) // Start a worker goroutine, give it the channel to go worker(done) // notify on. - <- done // Block until we can receive a value from the worker + <- done // Block until we can receive a value from the worker } // over the channel. /* diff --git a/xxx-line-filter.go b/xxx-line-filter.go index ee6caf3..4daed55 100644 --- a/xxx-line-filter.go +++ b/xxx-line-filter.go @@ -16,7 +16,7 @@ func main() { out := os.Stdout for { // If succesful, each `ReadLine` returns bytes and a - inBytes, pfx, err := in.ReadLine() // boolean indicating if don't have the whole line. + inBytes, pfx, err := in.ReadLine() // boolean indicating if don't have the whole line yet. if err == io.EOF { // The `EOF` error is expected when we reach the end return // of the input, so exit gracefully in that case.