gpt4 book ai didi

go - go lang中if语句错误中缺少条件

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

我的 if 语句未正确评估:

// Take advantage of Boolean short-circuit evaluation
if h != 2 && h != 3 && h != 5 && h != 6 && h != 7 && h != 8
{
fmt.Println("Hello")
}
return 0

这是错误信息-

missing condition in if statement

我已经试过把条件放在括号里等等

最佳答案

您需要将 { 放在 if 的末尾:

if h != 2 && h != 3 && h != 5 && h != 6 && h != 7 && h != 8 {
fmt.Println("Hello")
}
return 0

参见 this example .
另请参见“Why does Golang enforce curly bracket to not be on the next line?”。

关于go - go lang中if语句错误中缺少条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27190490/

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