CoCoA:Repeat

From ApCoCoAWiki

Repeat

loop command

Description

In the first form, the command sequence C is repeated until B

evaluates to FALSE. Unlike the While command, C is executed at

least once. Note that there is no EndRepeat following B. In the second form, the command sequence C is repeated until a Break or Return is encountered within C.

Example

  Define GCD_Euclid(A,B)
    Repeat
      R := Mod(A,B);
      A := B;
      B := R;
    Until B = 0;
    Return A
  EndDefine;

  GCD_Euclid(6,15);
3
-------------------------------
  N := 0;
  Repeat
    N := N+1;
    PrintLn N;
    If N = 5 Then Return; EndIf;
  EndRepeat;
1
2
3
4
5

-------------------------------

Syntax

Repeat C Until B
Repeat C EndRepeat

where C is a sequence of commands and B is a boolean expression.

For

Foreach

While

   <type>programming</type>
   <type>loops</type>