Same issue today. I get the same error on the “before else”. I tried the pragma but then I get lots of errors because defines like D4, INPUT_PULLUP etc, are not valid.
if (door_sense_rising_edge)
{
digitalWrite(door_open_pin, HIGH);
}
else if (door_sense_falling_edge)
{
digitalWrite(door_open_pin, LOW);
}
@bko I suppose that’s fine for a temporary work-around (although just dropping the else clause is also a work-around) I would hope that the Spark people will fix their compiler so it reliably compiles ‘else if’. What say you Spark people?
Just a quick clarification: the compiler in this case is the industry-standard gcc and it is working fine.
The only problem is the Spark pre-processor that lets novice coders write simpler code than the normal C/C++ rules would allow. I know you think of the compiler as being the thing that runs when you hit the button in the webIDE, but in reality there are two parts to it and only the first part has problems.
The reason your code is problematic for the pre-processor is that you are using a single value for the test of the if. If you re-write your code like this:
if (door_sense_rising_edge==true)
{
digitalWrite(door_open_pin, HIGH);
}
else if (door_sense_falling_edge==true)
{
digitalWrite(door_open_pin, LOW);
}
it will compile fine with the pre-processor.
The pre-processor does not work well with single value tests because it does not expect novices to write code that way. It is a bug for sure, but it is not some terrible bug, just a minor thing.