while

Description

A

while
loop will loop continuously, and infinitely, until the expression inside the parenthesis, () becomes false. Something must change the tested variable, or the while loop will never exit. This could be in your code, such as an incremented variable, or an external condition, such as testing a sensor.

Syntax

1while (condition) {
2 // statement(s)
3 }

Parameters

condition
: a boolean expression that evaluates to
true
or
false
.

Example Code

1var = 0;
2 while (var < 200) {
3 // do something repetitive 200 times
4 var++;
5 }

See also

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.