diff --git a/examples/channels/channels-with-functions.go b/examples/channels/channels-with-functions.go new file mode 100644 index 0000000..749b677 --- /dev/null +++ b/examples/channels/channels-with-functions.go @@ -0,0 +1,35 @@ +//In this example, we give a boolean value into a channel by calculating an another channel +//If the integer channel(the value is random) is divided into two, the value of boolean channel will be false +//otherwise it will be true +package main + +import ( + "fmt" + "math/rand" +) + +func channel_examples(number chan int, state chan bool) { + + number_value := <-number + state_value := <-state + + if number_value%2 == 0 { //if the number is divided into two + state_value = false + } + + fmt.Println(number_value, state_value) + +} + +func main() { + + number := make(chan int) + state := make(chan bool) + + go func() { + number <- rand.Intn(10) + state <- true + }() + channel_examples(number, state) + +}