vendredi 7 juin 2019

Else statement not working at the end of a while loop

When I go to compile the code it comes up with an error that there is no if statement before the else statement - I am using a while loop.

I have compiled the code before hand and it worked fine but as I just tried to upload it I received this error. When changing the while loop to an if statement the code compiles, is this a software issue maybe?

void loop() {

  distance = ultraSonic();

  // check if something is infront of hack-e-bot
  while (distance <= 2) {

    // turn hack-e-bot
    turning();
    distance = ultraSonic(); // check if there is still an obstruction

  } else {

    forward();
    distance = ultraSonic(); // check if there is still an obstruction

  }

}

Aucun commentaire:

Enregistrer un commentaire