Progress
Language Tutorial
for Windows


Using the REPEAT Block

The REPEAT block provides implicit looping and frame allocation, as well as syntax options for explicit looping and frame allocation. This is the syntax for the REPEAT block.

SYNTAX
[ label: ] 
  REPEAT  [ variable = expression1 TO expression2 ]
          [ WHILE expression ]
          { [ frame-phrase ] } :
  END 

Like the DO block, the REPEAT block can define the iterations of the block by incrementing a variable to a desired value or by specifying a WHILE expression. If the block contains neither of these options, then the REPEAT block loops continuously. In other words, there is no implicit terminating condition.

Progress provides the user with an implicit method of ending the iterations of a REPEAT block: the END-ERROR key. This feature makes REPEAT useful for coding repetitive tasks, especially where you cannot predict how many iterations of the task the user will want to complete. The terminating condition is in the hands of the user. By default, Progress displays a message instructing the user to press END-ERROR to end the block.

You can also programmatically control the end of a REPEAT block using the LEAVE statement. The LEAVE statement is useful when you want to evaluate a condition within a REPEAT block and exit the block based on the outcome. After Progress encounters the LEAVE statement, it continues execution with the first statement after the end of the block.

This exercise uses a REPEAT block to type characters in a fill-in field. Follow these steps for a demonstration of the REPEAT block:

  1. Open lt-06-04.p and run it. The following display appears:
  2. As soon as the interface displays, the letters of the alphabet quickly fill the Alphabet field. Of course, if you have a very fast computer, you may only see the end result of the loop—the entire alphabet.

  3. Choose Exit, then press SPACEBAR to return to the Procedure Editor.

Here is the code that created the display:

lt-06-04.p
      /**********  DEFINE WIDGETS  **********/
      DEFINE VARIABLE i AS INTEGER.
      DEFINE VARIABLE Alphabet AS CHARACTER FORMAT "x(30)".
      DEFINE BUTTON btn-Exit LABEL "Exit".
 
      /**********  DEFINE FRAME  **********/
      DEFINE FRAME Frame1
          SKIP(1)
          Alphabet SKIP(1)
          btn-Exit
              WITH SIDE-LABELS NO-BOX CENTERED THREE-D.
 
      /**********  MAIN LOGIC  **********/
/*1*/  ASSIGN i = ASC("a").
      ENABLE ALL WITH FRAME Frame1. 
       REPEAT:
/*2*/      APPLY CHR(i) TO Alphabet.
/*3*/      IF CHR(i) = "z" THEN
            LEAVE.
        i = i + 1.
       END. 
      WAIT-FOR CHOOSE OF btn-Exit. 

These notes help explain the code:

  1. The ASC function returns the integer code for a single character. (The integer value is interpreted from the current character set)
  2. The CHR function returns the character equivalent of an integer code. Applying a character to a fill-in field is equivalent to a user typing that character.
  3. When the loop reaches “z,” the LEAVE statement terminates the loop.

In addition, the REPEAT block:


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095