Boolean variable with if statement
I asked this question to be moved to Stackoverflow as it is not Arduino related.

However to answer your question, you assign the booleans before you start the program, so they are never re-evaluated and always keep their initial value, based on when x = 0.

What you should do is, reevaluate them within the loop:

int x = 0;
boolean state1;
boolean state2;

void setup() {
  Serial.begin(9600);
}

void loop() {
  x++;
  state1 = (x &lt;= 10);
  state2 = (x &gt; 10);
  if (state1) {
    Serial.println("x &lt;= 10");
  } else if (state2) {
    Serial.println(" x &gt; 10");
  }
}


Also, because if state1 is true, state2 will always be false and vice versa, so you don't need to have two booleans. This will give:

int x = 0;
boolean state;

void setup() {
  Serial.begin(9600);
}

void loop() {
  x++;
  state = (x &lt;= 10);
  if (state) {
    Serial.println("x &lt;= 10");
  } else {
    Serial.println(" x &gt; 10");
  }
}


Beyond that, you don't need to define the boolean globally, because you only need it inside the loop and is not need to be 'stored' from one loop to another. So you get

int x = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  x++;
  boolean state = (x &lt;= 10);
  if (state) {
    Serial.println("x &lt;= 10");
  } else {
    Serial.println(" x &gt; 10");
  }
}


Of course you can also directly check for x &lt;= 10 instead of storing it in a boolean, but I assume you need the boolean elsewhere further within the loop function later.