Home > Enterprise >  What does a while loop whith just condition and without statements in body means?
What does a while loop whith just condition and without statements in body means?

Time:03-01

In an arduino c program i have found there is a line of code which is while(digitalRead(x==LOW)); delay(100);

I can't understand what a loop just with the condition and nobody to execute, mean!

Need your support to get this

CodePudding user response:

It means "keep checking until the condition we're testing changes." Eventually, the state of the system is expected to change (e.g. somebody presses a button or something) and the loop condition fails, causing the loop to exit.

while(digitalRead(x==LOW)); delay(100); 

This looks like it almost certainly is supposed to be:

while(digitalRead(x==LOW)) {
    delay(100);
}

so that the delay is executed every time through the loop, slowing down the frequency of checking. The code will probably still work and just check the condition far more often than intended.

  • Related