While statement

Navigation:  Les scripts > Les autres scripts > Statements >

While statement

Previous pageReturn to chapter overviewNext page

A while statement is similar to a repeat statement, except that the control condition is evaluated before the first execution of the statement sequence. Hence, if the condition is false, the statement sequence is never executed.

The syntax of a while statement is

 

while expression do statement

 

where expression returns a Boolean value and statement can be a compound statement. The while statement executes its constituent statement repeatedly, testing expression before each iteration. As long as expression returns True, execution continues.

Examples of while statements include

 

while Data[I] <> X do I := I + 1;

while I > 0 do

 

begin

 if Odd(I) then Z := Z * X;

 I := I div 2;

 X := Sqr(X);

end;

 

while not Eof(InputFile) do

 

begin

 Readln(InputFile, Line);

 Process(Line);

end;