while statements |
Top Previous Next |
while statements
A while statement is used to repeat a statement or a block, while a control condition (expression) is evaluated as true.The control condition is evaluated before the statement. Hence, if the constrol condition is false at first iteration, the statement sequence is never executed. The while statement executes its constituent statement (or block) repeatedly, testing expression before each iteration. As long as expression returns True, execution continues.
Examples:
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; |