repeat statements until bool-expr;
The repeat
loop executes the statement sequence statements until the
condition bool-expr evaluates to true
.
First statements are executed. Then bool-expr is evaluated. If it
evaluates to true
the repeat
loop terminates and the statement
immediately following the repeat
loop is executed next. Otherwise if
it evaluates to false
the whole process begins again with the execution
of the statements.
The difference between the while
loop (see While) and the repeat
until
loop is that the statements in the repeat until
loop are
executed at least once, while the statements in the while
loop are
not executed at all if bool-expr is false
at the first iteration.
If bool-expr does not evaluate to true
or false
a error is
signalled and a break loop (see Break Loops) is entered. As usual you
can leave the break loop with quit;
. If you enter return true;
,
execution continues with the next statement immediately following the
repeat
loop. If you enter return false;
, execution continues at
statements, after which the next evaluation of bool-expr may cause
another error.
gap> i := 0;; s := 0;; gap> repeat > i := i + 1; s := s + i^2; > until s > 200; gap> s; 204 # first sum of the first i squares larger than 200
GAP 3.4.4