...

/

Solution Review: Sum of Squares

Solution Review: Sum of Squares

Let's go over the solution of the Sum of Squares problem using `select` statements.

We'll cover the following...
Press + to interact
package main
import "fmt"
func SumOfSquares(c, quit chan int) {
y := 1
for {
select {
case c <- (y*y):
y++
case <-quit:
return
}
}
}
func main() {
mychannel := make(chan int)
quitchannel:= make(chan int)
sum:= 0
go func() {
for i := 1; i <= 5; i++ {
sum += <-mychannel
}
fmt.Println(sum)
quitchannel <- 0
}()
SumOfSquares(mychannel, quitchannel)
}

Let’s go over the changes we made to the ...

Access this course and 1400+ top-rated courses and projects.