Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go {}和i之间的差值=0;i++;{}在围棋中_Go - Fatal编程技术网

Go {}和i之间的差值=0;i++;{}在围棋中

Go {}和i之间的差值=0;i++;{}在围棋中,go,Go,我现在正在学围棋。我正在读《围棋编程入门》一书 我在并发部分,从我的理解来看,我可以用两种方式定义一个无限循环和一个go程序 func pinger(c chan string) { for i := 0; ; i++ { c <- "ping" } } func printer(c chan string) { for { msg := <- c fmt.Println(msg) time.Slee

我现在正在学围棋。我正在读《围棋编程入门》一书

我在并发部分,从我的理解来看,我可以用两种方式定义一个无限循环和一个go程序

func pinger(c chan string) {
    for i := 0; ; i++ {
        c <- "ping" 
    }
}

func printer(c chan string) {
   for {
       msg := <- c
       fmt.Println(msg)
       time.Sleep(time.Second * 1)
   }
}
func pinger(c chan字符串){
对于i:=0;;i++{
c最好的方法是编写易于阅读和维护的代码。您在
func pinger
中的变量
i
没有任何作用,以后遇到该代码的人将很难理解它的用途

我会的

func pinger(c chan string) {
  for {
    c <- "ping" 
  }
}
func pinger(c chan字符串){
为了{
c最好的方法是编写易于阅读和维护的代码。您在
func pinger
中的变量
i
没有任何作用,以后遇到该代码的人将很难理解它的用途

我会的

func pinger(c chan string) {
  for {
    c <- "ping" 
  }
}
func pinger(c chan字符串){
为了{

c第一个循环中的
i
是冗余的;最好总是去掉未使用的变量,因此在pinger()函数中也应该为{}
使用

以下是一个工作示例:

package main

import(
 "time"
 "fmt"
)

func main() {
    c := make(chan string)
    go printer(c)
    go pinger(c)
    time.Sleep(time.Second * 60)
}

func pinger(c chan string) {
    for{
        c <- "ping" 
    }
}

func printer(c chan string) {
   for {
       msg := <- c
       fmt.Println(msg)
       time.Sleep(time.Second * 1)
   }
}
主程序包
进口(
“时间”
“fmt”
)
func main(){
c:=制造(成串)
go打印机(c)
go pinger(c)
时间。睡眠(时间。秒*60)
}
func pinger(c chan字符串){
为了{

c第一个循环中的
i
是冗余的;最好总是去掉未使用的变量,因此在pinger()函数中也应该为{}
使用

以下是一个工作示例:

package main

import(
 "time"
 "fmt"
)

func main() {
    c := make(chan string)
    go printer(c)
    go pinger(c)
    time.Sleep(time.Second * 60)
}

func pinger(c chan string) {
    for{
        c <- "ping" 
    }
}

func printer(c chan string) {
   for {
       msg := <- c
       fmt.Println(msg)
       time.Sleep(time.Second * 1)
   }
}
主程序包
进口(
“时间”
“fmt”
)
func main(){
c:=制造(成串)
go打印机(c)
go pinger(c)
时间。睡眠(时间。秒*60)
}
func pinger(c chan字符串){
为了{

c第一个循环中的
i
是冗余的。你可以/应该在
pinger()
函数中为{}
使用
。你在哪里找到这个例子的
i
?不要再看那里了。第一个循环中的
i
是冗余的。你可以/应该在
pinger()中为{}
使用
功能也一样。你在哪里找到这个带有
i
的示例的?不要再看了。谢谢你的答案!谢谢你的答案!谢谢你的答案,它非常有意义!谢谢你的答案,它非常有意义!