Progress
Language Reference


REPEAT Statement

Interfaces
OS
SpeedScript
All
All
Yes

Begins a block of statements that are processed repeatedly until the block ends in one of several ways.

BLOCK PROPERTIES

Iteration, record scoping, frame scoping, transactions by default.

SYNTAX

[ label : ] REPEAT
  [ FOR record [ , record ] ... ]
  [ preselect-phrase ]
  [ query-tuning-phrase ]
  [ variable = expression1 TO expression2 [ BY k ] ]
  [ WHILE expression ]
  [ TRANSACTION ] 
  [ on-endkey-phrase ]
  [ on-error-phrase ]
  [ on-quit-phrase ]
  [ on-stop-phrase ]
  [ frame-phrase ] 

FOR record [ , record ] . . .

Names a record buffer and scopes the buffer to the block. The scope of a record determines when the buffer is cleared and the record is written back to the database. See the Progress Programming Handbook for more information on record scoping and blocks.

To access a record in a table defined for multiple databases, you must qualify the record’s table name with the database name. See the Record Phrase reference entry for more information.

preselect-phrase

Goes through a table to select the records that meet the criteria you specify in a record-phrase. PRESELECT creates a temporary index that contains pointers to each of the preselected records in the database table. You can then use other statements, such as FIND NEXT, to process those records. This is the syntax for preselect-phrase.

SYNTAX
PRESELECT 
  [ EACH | FIRST | LAST ] record-phrase
    [ , { EACH | FIRST | LAST } record-phrase ] ...
  [ [ BREAK ] { BY expression [ DESCENDING ] } ... ] 

For more information, see the PRESELECT Phrase reference entry.

query-tuning-phrase

Allows programmatic control over the execution of a DataServer query.

SYNTAX
QUERY-TUNING
  (
    [ BIND-WHERE | NO-BIND-WHERE ]
    [ CACHE-SIZE integer ] 
    [ DEBUG { SQL | EXTENDED } | NO-DEBUG ]
    [ INDEX-HINT | NO-INDEX-HINT ] 
    [ JOIN-BY-SQLDB | NO-JOIN-BY-SQLDB ] 
    [ LOOKAHEAD | NO-LOOKAHEAD ]
    [ SEPARATE-CONNECTION | NO-SEPARATE-CONNECTION ]
  ) 

For more information, see the Progress DataServer Guides , Progress DataServer for ODBC Guide and Progress DataServer for ORACLE Guide.

variable = expression1 TO expression2 [ BY k ]

Indicates the name of a field or variable whose value you are incrementing in a loop. The expression1 is the starting value for variable on the first iteration of the loop. The k is the amount to add to variable after each iteration and must be a constant. When variable exceeds expression2 (or is less than expression2 if k is negative), the loop ends. Because expression1 is compared to expression2 at the start of the first iteration of the block, the block can be executed zero times. The expression2 is reevaluated with each iteration of the block.

WHILE expression

Indicates the condition during which the REPEAT block processes the statements within it. The block iterates as long as the condition specified by the expression is TRUE. The expression is any combination of constants, field names, and variable names that yield a logical value.

TRANSACTION

Identifies the REPEAT block as a system transaction block. Progress starts a system transaction for each iteration of a transaction block if there is no active system transaction. See the Progress Programming Handbook for more information on transactions.

on-endkey-phrase

Describes the processing that takes place when the ENDKEY condition occurs during a block. This is the syntax for the ON ENDKEY Phrase.

SYNTAX
ON ENDKEY UNDO
  [ label1 ]
  [     , LEAVE [ label2 ]
     |  , NEXT [ label2 ]
     |  , RETRY [ label1 ]
     |  , RETURN [ ERROR | NO-APPLY ] [ return-string ] 
  ]  

For more information, see the ON ENDKEY Phrase reference entry.

on-error-phrase

Describes the processing that takes place when there is an error during a block. This is the syntax for the ON ERROR Phrase.

SYNTAX
ON ERROR UNDO
  [ label1 ]
  [     , LEAVE [ label2 ]
     |  , NEXT [ label2 ]
     |  , RETRY [ label1 ]
     |  , RETURN [ ERROR | NO-APPLY ] [ return-string ] 
  ]  

For more information, see the ON ERROR Phrase reference entry.

on-quit-phrase

Describes the processing that takes place when a QUIT statement is executed during a block. This is the syntax for the ON QUIT Phrase.

SYNTAX
ON QUIT 
  [ UNDO [ label1 ] ]
  [     , LEAVE [ label2 ]
     |  , NEXT [ label2 ]
     |  , RETRY [ label1 ]
     |  , RETURN [ ERROR | NO-APPLY ] [ return-string ] 
  ]  

For more information, see the ON QUIT Phrase reference entry.

on-stop-phrase

Describes the processing that takes place when the STOP conditions occurs during a block. This is the syntax for the ON STOP Phrase.

SYNTAX
ON STOP UNDO
  [ label1 ]
  [     , LEAVE [ label2 ]
     |  , NEXT [ label2 ] 
     |  , RETRY [ label1 ]
     |  , RETURN [ ERROR | NO-APPLY ] [ return-string ] 
  ]  

For more information, see the ON STOP Phrase reference entry.

frame-phrase

Specifies the overall layout and processing properties of a frame. For more information, see the Frame Phrase reference entry.

EXAMPLE

In this menu procedure, if you press END-ERROR or ENDKEY when the procedure prompts you for your menu selection, any data you have entered as a selection is undone and the procedure continues to prompt you for a menu selection.

r-rpt.p
DEFINE VAR Selection AS INTEGER FORMAT "9".

FORM skip(3)
      "0 - Exit" at 32
      "1 - Edit Customer File" at 32
      "2 - List Customer File" at 32
      "3 - Edit Item File" at 32
      "4 - List Item File" at 32
      "Enter Choice" TO 30 Selection AUTO-RETURN
      HEADER "Application Name"  "Master Menu" AT 34  "Company" TO 79
      WITH NO-BOX NO-LABELS CENTERED FRAME menu.

/* Create the procedures that are called from the following block. */

REPEAT ON ENDKEY UNDO, RETRY:
    UPDATE Selection WITH FRAME menu.
    HIDE FRAME menu.

    CASE(Selection):
      WHEN 0 THEN
        LEAVE.
      WHEN 1 THEN
        RUN custedit.p.
      WHEN 2 THEN
        RUN custrpt.p.
      WHEN 3 THEN
        RUN itemedit.p.
      WHEN 4 THEN
        RUN itemrpt.p.
      OTHERWISE DO:
        BELL.
        MESSAGE "Not a valid choice. Try again.".
      END.
    END CASE.

END.  /* REPEAT  */ 

NOTES

SEE ALSO

DO Statement, END Statement, Frame Phrase, ON ENDKEY Phrase, ON ERROR Phrase, ON QUIT Phrase, ON STOP Phrase


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