what wrong with my if statement

Hi everyone a newbee programming question, why do i get errors trying to compile with my if statement the error in the ardunio complier is " expected initializer before 'if'"

the 'smode' variable is delared at the top of my code with pin assiginments and stuff as a global variable

#include <avr/pgmspace.h>
#define bl_inc 10
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 3 on the Arduino
#define ONE_WIRE_BUS 3
#define TEMPERATURE_PRECISION 9
// mills() delay
unsigned long timer1 = 0;
///
        int motorPin = 11;//pwm fan control
  const int vent1Pin = 8;//Summer damper
  const int vent2Pin = 9; //roof damper
  const int vent3Pin = 7;//heat transfer
  int smode = 0;

then at the top of my loop code i try to test the 'smode' variable with a simple if else statement.

void loop()

if (smode == 0)
{
     digitalWrite(9, HIGH);
}
else{
 digitalWrite(9,LOW);
}

can someone please point out my syntax error because i read the code as i have assigned the variable 'smode' to '0' up at the top of my code as a global variable then in the loop the if statement should be comparing if 'smode' is still '0' then it can do stuff? but i cant compile with the if statement because of the complier error.

sketch_dec08a:120: error: expected initializer before 'if'
sketch_dec08a:124: error: expected unqualified-id before 'else'

this the lines with my if statement that contains the error

cheers for your help

That error means there is something wrong before the if statement. In your case you have not put { } round your loop() function body.

thanks grumpy!

Side note: I think you can actually get rid of the if statement entirely and just do this:

void loop()
{
    digitalWrite( 9, !smode );
}

As I understand it, booleans are actually just integers where 0 is equivalent to false and anything else equals true. So if smode is zero it reads as false, and then the ! reverses it to true (non-zero), which digitalWrite will read as HIGH. Likewise, if it's not zero (true), the ! will reverse it to zero (false) and digitalWrite will see it as LOW.

you need have the loop() section in {}.
void loop()
{

// your if statement here

}