Go Down

Topic: semi colon after if statement (Read 1 time) previous topic - next topic

PhayilBoy

what is the effect of putting a semi colon on an if statement? I'm sure this used to flag as an error (before version 1.0) but it doesn't any more and code seems to function differently with it/without it. so I was wondering what is meant to happen when you do this? (I hope that makes sense)
Code: [Select]

void loop()
{
if(a >= b);
  {
    digitalWrite(13, LOW);
  }
}
   
the code is not relevant just an example

PaulS

Quote
I'm sure this used to flag as an error (before version 1.0) but it doesn't any more and code seems to function differently with it/without it.

No, it didn't, and yes, it does.

The ; after the if() statement becomes the empty body of the if statement. Only the empty body will be executed, meaning that nothing happens.

dxw00d

And this is executed unconditionally:
Code: [Select]
  {
    digitalWrite(13, LOW);
  }

PhayilBoy

Ahh i see now, thanks that explains nicely  XD

Go Up