3

I have this if statement that is not evaluating correctly:

// 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

This is the error message -

missing condition in if statement

I have already tried putting the conditions in brackets etc.

Varun
  • 1,013
  • 3
  • 17
  • 28
  • 4
    I'm also learning Go currently. I have found that using Gofmt really cuts down, or eliminates entirely, this type of error. Good luck...https://golang.org/cmd/gofmt/ – user1503949 Nov 28 '14 at 14:23
  • yeah, I should start doing that, right now I run the programs directly in sublime.. – Varun Nov 28 '14 at 14:28
  • I've been using LiteIDE, which can also run your Go code directly, but it will apply Gofmt before compiling, which is nice. Anyhow, good luck with it. – user1503949 Nov 28 '14 at 14:47
  • @Varun Install https://github.com/DisposaBoy/GoSublime is a sublime extension for go that (among other wonderful things) calls gofmt automatically before saving your file so each time you save it gets formatted automatically. – Topo Nov 28 '14 at 16:14

2 Answers2

10

You would need to put the { at the end of the if:

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

See this example.
See also "Why does Golang enforce curly bracket to not be on the next line?".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

You must have to put Curly Braches right after the if condition like this:

Right example

if(condition){
<code comes here>
}

Wrong example

if(condition)
{
<code comes here>
}
Om Sao
  • 7,064
  • 2
  • 47
  • 61