Back: Loops Forward: for   FastBack: Conditionals Up: Loops FastForward: Scoping         Top: Yorick Contents: Table of Contents Index: Concept Index About: About this document The while and do while statements

The while loop is simpler than the for loop:

while (condition) body_statement

The body_statement -- very oten a compound statement enclosed in curly braces -- executes over and over until the condition becomes false. If the condition is false to begin with, body_statement never executes.

Occasionally, you want the body_statement to execute and set the condition before it is tested for the first time. In this case, use the do while statement:

do {
 } while (condition);