A while loop is a block of code that is executed repeatedly until some condition is met. Its structure is:
while(expression) {
statements
}
As with an if statement, the expression in parentheses is evaluated first. If it evaluates to non-zero, the statements in the body of the loop are executed. At the end of the loop body, the expression is evaluated again, and the body is executed until the expression evaluates to 0. The expression is normally relational, depending on some value that is being updated in the loop.
u08 button;
while (button != 1) { // while the value of button is not equal to 1
button = checkButton(3); // call the function checkButton with
// argument 3, and assign its value to
// the variable button
}
This loop will execute until the function checkButton(3) returns a 1. This type of structure is common for polling an input.