REPEAT CYCLE

Back to:
index

This cycle reiterates its contents until the condition in its end becomes TRUE. After it cycle ends.

REPEAT cycle is even easier than WHILE one, so if you understand previous construction well, you'll have no difficulties with REPEAT.

Meeting REPEAT reserved word in the text of Pascal program, compiler remembers the address of current instruction in equivalent code and then continues translation process as usual. When UNTIL construction is found, "ComPas" translates a condition after it and adds correspondent conditional jump to previously remembered address (condition analysis compiling is described on special page).

Examples and operator structure

"E97" code example

Intel code example


Examples and operator structure

Typical examples of REPEAT cycle, available in "COMPAS" are the following:

  • REPEAT i := i + 1 UNTIL s[i] = '#';
  • REPEAT s := s + a; a := a + 1 UNTIL a < 10;
  • REPEAT READ(c) UNTIL c='.';
  • REPEAT w := w-1; b := w=0 UNTIL b;

Possible structures of this operator can be written the following way:

REPEAT {operator} UNTIL {condition} ;

REPEAT {operator} UNTIL {BOOLEAN variable} ;

Note, in the case of REPEAT cycle you have no need to use reserved words BEGIN and END to group cycle body operators.

REPEAT scheme



Back to:
index top E97 Intel


E97 code example

REPEAT {cycle's body} UNTIL x=8 ; (DE - address of variable x)
Address, codeOperationsPascal comments
0012
...
0024
{cycle's body}
0026 01E1
0028 00DE
(DE) ==> R1 Extract x
002A 2481 compare R1 with const 8 Is x = 8 ?
002C 4C0D
002E 0012
jump if <> 0 Repeat cycle if FALSE



Back to:
index top Intel


Intel code example

REPEAT {cycle's body} UNTIL x=8 ; (4FE - address of variable x)
Address, codeOperationsPascal comments
28C
...
2A0
{cycle's body}
2A1 A1 FE 04 mov ax,[4FE] Extract x
2A4 B9 08 00
2A7 39 C8
mov cx,8
cmp ax,cx
Is x = 8 ?
2A9 75 E1 jnz 28C (if <> 0) Repeat cycle if FALSE



Back to:
index top E97