Created
January 29, 2014 03:47
-
-
Save kamoljan/8681485 to your computer and use it in GitHub Desktop.
How to use Go Channel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func print(i int) string { | |
if i%3 == 0 { | |
if i%5 == 0 { | |
return fmt.Sprintf("%d PipipiPopopo\n", i) | |
} | |
return fmt.Sprintf("%d Popopo\n", i) | |
} else if i%5 == 0 { | |
return fmt.Sprintf("%d Pipip\n", i) | |
} | |
return fmt.Sprintf("%d\n", i) | |
} | |
func loop(f int, t int, c chan string) { | |
x := "" | |
for i := f; i <= t; i++ { | |
x = x + print(i) | |
} | |
c <- x | |
} | |
func main() { | |
c := make(chan string) | |
go loop(1, 50, c) | |
go loop(51, 100, c) | |
fmt.Println(<-c, <-c) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment