while Keyword

The while keyword is al part of while (described below) and do-while statements.

while Statement

The while statement lets you repeat a statement until a specified expression becomes false.

Syntax

while ( expression ) statement

The expression must have arithmetic (numeric/boolean) type. Execution proceeds as follows:

  1. The expression is evaluated.

  2. If expression is initially false, the body of the while statement is never executed, and control passes from the while statement to the next statement in the program.

    If expression is true (nonzero), the body of the statement is executed and the process is repeated beginning at step 1.

This is an example of the while statement:

i = 10;
while( i < 20 )
{
  Plot( MA( Close, i ), "MA" + WriteVal( i, 0 ), colorBlack + i );
  i = i + 1;
}

The example plots 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 - bar moving averages.