dongpankao6133 2014-04-08 21:23
浏览 127

GoLang == true已评估,但未使用

Inside the code, I try to do some operations

is_html := false;

// Check, if HTMl is exist 
for i := 0; i < len(modules_arr); i++ { 
    if modules_arr[i] == "html" { is_html := true }

}

if is_html ==true
{
    fmt.Printf("%v", "asdasd")
}

But I get an error:

./api.go:26: missing condition in if statement
./api.go:26: is_html == true evaluated but not used
Error: process exited with code 2.
  • 写回答

4条回答 默认 最新

  • dongsicheng5262 2014-04-08 21:34
    关注

    if statements needs the { on the same line in go

    This means you cannot do

    if is_html ==true
    {
        fmt.Printf("%v", "asdasd")
    }
    

    The correct code is

    if is_html ==true {
        fmt.Printf("%v", "asdasd")
    }
    

    Read http://golang.org/doc/effective_go.html#semicolons for a better understanding

    评论

报告相同问题?