Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The "break statement" is just not working like it should

This is the code but for some reason, when (distancia<100) the ("ALTO") still appears, and the same with the other while loop

while (distancia<200 && distancia>100)
{
    lcd.print("ALTO");
    delay(1000);
    lcd.clear();
    delay(1000);

  if(distancia<100)
  {
    break;
 }
}
 while(distancia<100)
  {
    lcd.print("INTRUSO EN");
    lcd.setCursor(0,1);
    lcd.print("LA PUERTA");
    tone(11,700,250);
    digitalWrite(8,HIGH);
    delay(500);
    lcd.clear();
    digitalWrite(8,LOW);
    delay(500);

    if(distancia>100);
    {
       break;
    }
}
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

this is your while loop:

while (distancia<200 && distancia>100)

and this is your if:

if(distancia<100);
{
   break;
}

a variable can’t be greater and smaller than 100 at the same time so that if is basically useless

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading