Exit While loop

Sorry for the noob question but I can’t exit the while loop. I have a variable called control which take the timestamp value from the internet. I need to execute some functions when control is between 2 values and then when control is between other 2 values I need to change while loop. Anyway even when control is between soglia2 and soglia3 the first while loop keeps going.
What am I missing? Thanks a lot

while (control >= soglia1 && control <soglia2){
     Serial.println("Entering second slot");
      Serial.println("Enter modem sleep mode");

  while (control >= soglia2 && control < soglia3){
    //do something
     Serial.println("Entering third slot");
    Serial.println("Exit modem sleep");

My guess is that you are not changing ‘control’, ‘soglia1’, ‘soglia2’, or ‘soglia3’ inside the loop. That mean once the condition is ‘true’ it will remain ‘true’ forever and the loop will continue while the condition is ‘true’ (forever). Perhaps you wanted ‘if’ statements instead of ‘while’ loops?


Take a look at “break” this might help you exit a while loop:Arduino Break

Actually that was the problem. To solve it I made a function that return the control value and I called it at the end of every while loop. Thanks a lot anyway!

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