HPlogo HP C/HP-UX Reference Manual: Workstations and Servers > Chapter 6 Statements

The while Statement

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

The while statement evaluates an expression and executes the loop body until the expression evaluates to false.

Syntax

while (expression)
statement

Description

The controlling expression is evaluated at run time. If the controlling expression has a nonzero value, the loop body is executed. Then control passes back to the evaluation of the controlling expression. If the controlling expression evaluates to 0, control passes to the statement following the loop body. The test for 0 is performed before the loop body is executed. The loop body of a while statement with a controlling constant expression that evaluates to 0 never executes.

Example

For example:

i = 0;
while (i < 3) {
func (i);
i++;
}

The example shown above calls the function func three times, with the argument values of 0, 1, and 2.