while loops are similar to if statements in that they run as long as a single expression or condition is true. Value comparisons and Boolean variables can be used as while conditions, and they can be modified with the NOT operator.
The while loop syntax says, While my condition is true, keep running my code block indefinitely:
initializer
while (condition)
{
code block;
iterator;
}
With while loops, it's common to declare an initializer variable, as in a for loop, and manually increment or decrement it at the end of the loop's code block. Depending on your situation, the initializer is usually part of the loop's condition.