I have some code like this:
go func(ch chan bool) chan bool {
// some processing
ch <- true
return ch
}(ch)
for i := 0; i < TotalQuestions; i++ {
// check if channel ch has some value
// If it has then execute below statements, else break out of the loop
fmt.Println(questions[i])
answer, _ := InputReader.ReadString('
')
// some processing
}
fmt.Println("Your Total score is " + strconv.Itoa(TotalScore) + " out of " + strconv.Itoa(TotalQuestions))
Now what I want to do is to check if channel ch has a value (in for loop). If it has a value then I want to break out of the for loop to print the last statement. otherwise, I want to continue my loop. I tried to insert select block but that didn't work (The channel got blocked and code didn't print questions). How to do that?