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.
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:
- Open
lt-06-04.p
and run it. The following display appears:
![]()
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.
- Choose Exit, then press SPACEBAR to return to the Procedure Editor.
Here is the code that created the display:
These notes help explain the code:
- The ASC function returns the integer code for a single character. (The integer value is interpreted from the current character set)
- 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.
- 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 |