
This could be in your code, such as an incremented variable, or an external condition, such as testing a sensor. Something must change the tested variable, or the while loop will never exit.

in the code posted below, the conditions to remain in. while experimenting with multiple conditions within do-while loops, i came across a strange phenomena that left me with no results via internet search. A while loop will loop continuously, and infinitely, until the expression inside the parenthesis, () becomes false. That is due to lazy evaluation of || and & in C, so that if the first expression is true, the rest will NOT be evaluated and thus their side effects will not happen. while experimenting with multiple conditions within do-while loops, i came across a strange phenomena that left me with no results via internet search. For loops are quite strong and can handle the majority of your looping requirements.
#ARDUINO WHILE LOOP MULTIPLE CONDITIONS HOW TO#
While with multiple conditions may have a problem in one case - if those multiple conditions actually have intended side effects. We learnt how to utilise for loops in Lesson 3. if b and c never change throughout the loop, in which case you need to cache the value of b!=1 in a variable). The only issue with yours is that it can sometimes be less than optimal (e.g. Under normal circumstances there's no problem whatsoever with the expression above (assuming you wanted to do just that). The correct way is ch != '\n' & ch != ' '.


If the character is a space, the first condition is true (since space is not newline) and the OR is true. If the character is NOT a space, the second condition is true so the OR is true. UPDATE: As per your other comment, your expression is wrong - it has nothing to do with "while" having multiple conditions.Ĭh != '\n' || ch != ' ' is ALWAYS true, no matter what the characters is.
