We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Range

Similar to slices and maps, channels can be ranged over.

for item := range ch {
    // item is the next value received from the channel
}

This example will receive values over the channel (blocking at each iteration if nothing new is there) and will exit only when the channel is closed.

Assignment

It's that time again, Textio is hiring and we've been assigned to do the interview. The Fibonacci sequence is Textio's interview problem of choice. We've been tasked with building a small toy program we can use in the interview.

Complete the concurrentFib function. It should:

The fibonacci function is the producer: it runs in its own goroutine and sends numbers into the channel. The concurrentFib function is the consumer: it reads all the numbers from that channel using a range loop and aggregates them.