Error code: unqualified id before if

Hi there, so I am basically a newcomer when it comes to Arduino and I have been trying but I am not sure what is wrong with this code. Can somebody help please?

if (distancia > 0) {
if (distancia < 30) {
if (distancia > 20) {
retrocede();
delay(200);
parada(100);
} else {
derecha();
delay(400);
parada(500);
}
} else {
avanza();
}
} else {
avanza();
}

The error says: expected unqualified id before "if"``

if (distancia > 0) {
  if (distancia < 30) {
    if (distancia > 20) {
      retrocede();
      delay(200);
      parada(100);
    }
    else {
      derecha();
      delay(400);
      parada(500);
    }
  }
  else {
    avanza();
  }
}
else {
  avanza();
}

Look vaguely familiar, placed in code tags?

Nothing wrong with that that I can see, so it must be the hidden code you didn't present. :person_shrugging:
You must have blown past this, or thought it didn't apply to you:

Help us help you, and please read How to get the best out of this forum and post accordingly (including code with code tags ).

As the compiler said, the issue is before the if, so we would need to see that part of the code (the full code).

Side note
Do you think that the both condition can match simultaneously?

I do :slight_smile: (any value in the interval ]20, 30[ would)

2 Likes

Face palm :slight_smile:

2 Likes

hand face?


:man_facepalming:

1 Like

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