Home Up Contents Search

REPEAT ... UNTIL loop

REPEAT ... UNTIL loop

The REPEAT and UNTIL statements form a general-purpose looping construct with the test for the terminating condition at the bottom of the loop.

Syntax:

REPEAT
<statement(s)>
UNTIL <boolean-expression>


As long as <boolean-expression> evaluates False, the statement(s) between REPEAT and UNTIL are executed. Note that the statements in the loop are always executed at least once. This is in contrast to the WHILE and FOR loops, which, depending on the initial values, might not execute even a single time. Also unlike FOR and WHILE loops, a begin/end block isn't required to execute more than one statement in the loop.

program RepeatUntilDemo;

uses Win32Crt;

var N : LongInt;

begin

repeat

Writeln('Press any Key to Stop');

until KeyPressed; { Returns True when a key is pressed... }


repeat

Write('Enter a number (99 to quit): ');
Readln(N);
Writeln('N * N' =, N*N);

until N = 99;

end. { RepeatUntilDemo }

 
Previous Next
Send mail to ljschwerin@hotmail.com with questions or comments about this web site.

Copyright © 1999-2002 Leon Schwerin
Last modified: 26 March 2000
1