REPEAT statement
- Last Updated: October 16, 2024
- 4 minute read
- OpenEdge
- Version 12.8
- Documentation
Begins a block of statements that are processed repeatedly until the block
ends. An END statement is used to terminate a REPEAT
block.
Syntax
This is the syntax for the REPEAT block:
|
- 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 written back to the database. See Develop ABL Applications 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 Record phrase for more information.
- preselect-phrase
-
Goes through a table to select the records that meet the criteria you specify in a record-phrase.
PRESELECTcreates a temporary index that contains pointers to each of the preselected records in the database table. You can then use other statements, such asFIND NEXT, to process those records. This is the syntax for the preselect-phrase:PRESELECT [ EACH | FIRST | LAST ]record-phrase [ , { EACH | FIRST | LAST }record-phrase]... [[ BREAK ]{ BY expression[ DESCENDING ]}...]For more information, see PRESELECT phrase.
- query-tuning-phrase
-
Allows programmatic control over the execution of a DataServer query. This is the syntax for the query-tuning-phrase:
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 OpenEdge DataServer Guides (Use the Microsoft SQL Data Server and Use the Microsoft SQL Data Server).
- variable = expression1 TO expression2 [ BY k ]
-
Indicates the name of a field or variable whose value you are incrementing in a loop. expression1 is the starting value for variable on the first iteration of the loop. 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. expression2 is reevaluated with each iteration of the block.
- WHILE expression
-
The
REPEATblock iterates as long as the condition specified by expression is TRUE. expression is any combination of constants, field names, and variable names that yield a logical value. - TRANSACTION
-
Identifies the
REPEATblock as a system transaction block. The AVM starts a system transaction for each iteration of a transaction block if there is no active system transaction. See Develop ABL Applications for more information on transactions. - stop-after-phrase
-
Specifies a time-out value (in seconds) for the block. This is the syntax for the
STOP-AFTERphrase:STOP-AFTER time-limitFor more information see STOP-AFTER phrase.
- on-endkey-phrase
-
Describes the processing that takes place when the ENDKEY condition occurs during a block. This is the syntax for the
ON ENDKEYphrase:ON ENDKEY UNDO [label1] [ , LEAVE [label2] | , NEXT [label2] | , RETRY [label1] | , RETURN [return-value| ERROR [return-value|error-object-expression]| NO-APPLY ]For more information see the ON ENDKEY phrase.
- on-error-phrase
-
Describes the processing that takes place when there is an error during a block. This is the syntax for the
ON ERRORphrase:ON ERROR UNDO [label1] [ , LEAVE [label2] | , NEXT [label2] | , RETRY [label1] | , RETURN [return-value| ERROR [return-value|error-object-expression]| NO-APPLY ] | , THROW ]For more information see the ON ERROR phrase.
- on-quit-phrase
-
Describes the processing that takes place when a
QUITstatement is executed during a block. This is the syntax for theON QUITphrase:ON QUIT [ UNDO [label1]] [ , LEAVE [label2] | , NEXT [label2] | , RETRY [label1] | , RETURN [return-value| ERROR [return-value|error-object-expression]| NO-APPLY ] ]For more information see the ON QUIT phrase.
- on-stop-phrase
-
Describes the processing that takes place when the
STOPconditions occurs during a block. This is the syntax for theON STOPphrase:ON STOP UNDO [label1] [ , LEAVE [label2] | , NEXT [label2] | , RETRY [label1] | , RETURN [return-value| ERROR [return-value|error-object-expression]| NO-APPLY ] ]For more information see the ON STOP phrase.
- frame-phrase
-
Specifies the overall layout and processing properties of a frame. This is the syntax for the frame phrase:
WITH [ ACCUM [ max-length ]] [ at-phrase ] [ CANCEL-BUTTON button-name][ CENTERED ] [ color-specification] [ COLUMN expression][n COLUMNS ] [ CONTEXT-HELP ][ CONTEXT-HELP-FILE help-file-name] [ DEFAULT-BUTTON button-name] [ DROP-TARGET ] [[expression] DOWN ][ EXPORT ] [ WIDGET-ID id-number][ FONT expression] [ FRAME frame] [ INHERIT-BGCOLOR | NO-INHERIT-BGCOLOR ] [ INHERIT-FGCOLOR | NO-INHERIT-FGCOLOR ] [ KEEP-TAB-ORDER ][ NO-BOX ] [ NO-HIDE ][ NO-LABELS ][ USE-DICT-EXPS ] [ NO-VALIDATE ][ NO-AUTO-VALIDATE ] [ NO-HELP ][ NO-UNDERLINE ] [ OVERLAY ][ PAGE-BOTTOM | PAGE-TOP ][ RETAIN n] [ ROW expression][ SCREEN-IO | STREAM-IO ] [ SCROLL n][ SCROLLABLE ][ SIDE-LABELS ] [ size-phrase][ STREAM stream| STREAM-HANDLE handle][ THREE-D ] [ title-phrase][ TOP-ONLY ][ USE-TEXT ] [ V6FRAME [ USE-REVVIDEO | USE-UNDERLINE ]] [ VIEW-AS DIALOG-BOX ][ WIDTH n][ IN WINDOW window]For more information, see the Frame phrase.
Example
In this menu procedure, if you press END-ERROR or ENDKEY when prompted for your menu selection, any selection data you have entered is undone and the procedure continues to prompt you:
r-rpt.p
|
Notes
- Within a
REPEATblock, if you are using theFIND NEXTorFIND PREVstatement and you change the value of an index field, the AVM makes that change in the index table at the end of theUPDATEorSETstatement. Therefore, if you change the value so that the record appears later in the index table, you see the record again if youFIND NEXT. If you change the value so that the record appears earlier in the index table, you see the record again if youFIND PREV.REPEAT: FIND NEXT Customer. UPDATE Customer.CustNum. END.In this example, if you change Customer 1 to Customer 300, you see that Customer record again at the end of the procedure.
When you use the
PRESELECToption, the AVM builds a special index table that is not updated when index values change:REPEAT PRESELECT EACH Customer: FIND NEXT Customer. UPDATE Customer.CustNum. END.In this example, if you change Customer 2 to Customer 200, you do not see that Customer record until you look it up with a new procedure.
- For SpeedScript, the on-endkey-phrase and on-quit-phrase are not valid options.
See also
DO statement, END statement, Frame phrase, ON ENDKEY phrase, ON ERROR phrase, ON QUIT phrase, ON STOP phrase, Record phrase, STOP-AFTER phrase