Исходники и презентации
This commit is contained in:
33
lessons/channels/select_with_break_and_continue/main.go
Normal file
33
lessons/channels/select_with_break_and_continue/main.go
Normal file
@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
data := make(chan int)
|
||||
go func() {
|
||||
for i := 1; i <= 4; i++ {
|
||||
data <- i
|
||||
}
|
||||
close(data)
|
||||
}()
|
||||
|
||||
for {
|
||||
value := 0
|
||||
opened := true
|
||||
|
||||
select {
|
||||
case value, opened = <-data:
|
||||
if value == 2 {
|
||||
continue
|
||||
} else if value == 3 {
|
||||
break
|
||||
}
|
||||
|
||||
if !opened {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println(value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user