while
Loops
The basic syntax for a while statement is:
while (logical-expression) statement
The statement repeated by the while loop can also be a compound statement:
while (logical-expression) { statement statement ... }
In either case, the statement(s) will be repeated as long as the logical expression evaluates to true.
This means that whatever is being evaluated better change, or you will have an infinite loop.
Two common ways to end a while loop are with a
sentinel
or a
break
statement.
A sentinel while loop continues until a specific value is entered (called a "sentinel").
A break statement breaks out of the current loop and continues execution from the end of the loop.