Instruction IF could not understand

Hi guys,

i could not follow up this problem ...

int Var = 0;

void setup() {
  // put your setup code here, to run once:
Serial.begin (115200);

}

void loop() {
  // put your main code here, to run repeatedly:
if (Var == 1)
{
  Serial.println ("VAR 111111111");
  delay (500);
}
if (Var == 0);
{
  Serial.println ("VAR 0000000000");
  delay (500);
}
}

Give me this result:
![Result VAR IF Statement|690x249](upload://p2NSWaqQYOoShUvz7wlfFiIUzJ2.png)


Please could someone explain me why, because of Var = 0, program is reading IF statement with condition if (Var == 1)...


Thanks for help

Regards

if (Var == 0);
What is that semicolon doing there ?

Thank you !!!

I tried again, and it works without semicolon,

there is no error in the program ...

Thanks

Regards

Do you understand why the semicolon caused a problem ?

no !

The semicolon ends the statement that is executed when the if returns true. You will note that there is actually no statement to be executed

However, the code in the curly brackets will be executed unconditionally whatever the result of the test

Sounds clear for me,

thanks for explanations,

Regards

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.