The WHILE ... DO loop is a general-purpose looping construct that puts the test for the terminating condition at the top
of the loop.
Syntax:
WHILE <boolean-expression>
DO
<statement>
As long as <boolean-expression> evaluates True, <statement> is executed; if <boolean-expression>
evaluates as False on the first pass, <statement> is never executed. This is in contrast to the REPEAT/UNTIL
loop, which always executes the statement(s) in the loop at least once.
As with the FOR loop, a begin/end block is necessary to execute more than one statement inside a WHILE loop.
program
WhileDemo;
uses
Win32Crt;
var N
: LongInt;
begin
while not KeyPressed do { a semi-infinite loop }
Write('--Press any key to stop--');
Writeln; Writeln;
Write('Enter a number (99 to quit): ');
Readln(N);
While
N <> 99 do
begin
Writeln('N * N =', N*N);
Write('Enter a number (99 to quit): ');
Readln(N)
end;
end. { WhileDemo }