Created
April 3, 2014 14:42
-
-
Save xyhp915/9955633 to your computer and use it in GitHub Desktop.
go play
This file contains 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 main() { | |
queue := []int{1, 2, 3, 4, 5} | |
ch := make(chan int) | |
go func() { | |
for _, val := range queue { | |
ch <- val | |
} | |
}() | |
var item int | |
for { | |
item = <-ch | |
if item == 5 { | |
fmt.Println("break loop") | |
break | |
} else { | |
fmt.Println(item) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment