@kjk1/

gobook range channel

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.26371240884400704","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgImZtdCIKCi8vIDpzaG93IHN0YXJ0CmZ1bmMgZmlsbEFuZENsb3NlQ2hhbm5lbChjaCBjaGFuIGludCkgewoJZm9yIGkgOj0gMDsgaSA8IDM7IGkrKyB7CgkJY2ggPC0gaSArIDMKCX0KCWNsb3NlKGNoKQp9CgovLyA6c2hvdyBlbmQKCmZ1bmMgbWFpbigpIHsKCS8vIDpzaG93IHN0YXJ0CgljaCA6PSBtYWtlKGNoYW4gaW50KQoJZ28gZmlsbEFuZENsb3NlQ2hhbm5lbChjaCkKCglmb3IgdiA6PSByYW5nZSBjaCB7CgkJZm10LlByaW50ZigidjogJWRcbiIsIHYpCgl9CgkvLyA6c2hvdyBlbmQKfQo="},"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
package main

import "fmt"

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

// :show end

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

	for v := range ch {
		fmt.Printf("v: %d\n", v)
	}
	// :show end
}