gpt4 book ai didi

go - 是否可以编写没有返回或 Nil 返回类型的函数。建议替代方案

转载 作者:IT王子 更新时间:2023-10-29 00:51:27 25 4
gpt4 key购买 nike

我这里有一个循环遍历并打印数字的函数。我没有任何返回。如何避免这种情况而不必返回值?

func Problem1V3() Nil {
sum := 0
for i := 3; i < 1000; i+=3 {
fmt.Printf("i loop: %v", i)
}
return Nil
}

最佳答案

我认为这应该可行。

func Problem1V3() {
for i := 3; i < 1000; i+=3 {
fmt.Printf("i loop: %v", i)
}
}

您可以在 http://play.golang.org/p/irUI1sCx_B 运行它

关于go - 是否可以编写没有返回或 Nil 返回类型的函数。建议替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20176162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com