Back: 1.2.4 Loops Forward: The for statement     FastBack: 1. Basic Ideas Up: 1.2.4 Loops FastForward: 2. Using Array Syntax         Top: Yorick: An Interpreted Language Contents: Table of Contents     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);