@kjk1/

gobook range channel 2

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.4941902849859412","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"CnBhY2thZ2UgbWFpbgoKaW1wb3J0ICJmbXQiCgpmdW5jIGZpbGxBbmRDbG9zZUNoYW5uZWwoY2ggY2hhbiBpbnQpIHsKCWZvciBpIDo9IDA7IGkgPCAzOyBpKysgewoJCWNoIDwtIGkgKyAzCgl9CgljbG9zZShjaCkKfQoKZnVuYyBtYWluKCkgewoJLy8gOnNob3cgc3RhcnQKCWNoIDo9IG1ha2UoY2hhbiBpbnQpCglnbyBmaWxsQW5kQ2xvc2VDaGFubmVsKGNoKQoKCWZvciB7CgkJdiwgb2sgOj0gPC1jaAoJCWlmICFvayB7CgkJCWJyZWFrCgkJfQoJCWZtdC5QcmludGYoInY6ICVkXG4iLCB2KQoJfQoJLy8gOnNob3cgZW5kCn0="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package main

import "fmt"

func fillAndCloseChannel(ch chan int) {
	for i := 0; i < 3; i++ {
		ch <- i + 3
	}
	close(ch)
}

func main() {
	// :show start
	ch := make(chan int)
	go fillAndCloseChannel(ch)

	for {
		v, ok := <-ch
		if !ok {
			break
		}
		fmt.Printf("v: %d\n", v)
	}
	// :show end
}