Previous Topic Next topic Print topic


% REPEAT

Establish a loop and test a condition.
Restriction: This topic applies only when the AppMaster Builder AddPack has been installed, and applies only to Windows platforms.

Syntax:

Format 1:

 % REPEAT
     statementblock
 % UNTIL|WHILE condition
    [statementblock]
[% END]

Format 2:

 % REPEAT VARYING|R-V &variable
 % ... [FROM &variable|literal|arithmeticexpr]
 % ... [BY &variable|literal|arithmeticexpr]
           statementblock
 % ... UNTIL|WHILE condition
           [statementblock]
[% END]

Format 3:

 % REPEAT VARYING|R-V &variable
 % ... [FROM &variable|literal|arithmeticexpr]
 % ... [BY &variable|literal|arithmeticexpr]
 % ... THRU|TO &variable|literal|arithmeticexpr
[% ... OR THRU|TO &variable|literal|arithmeticexpr]
[% ... OR THRU|TO &variable|literal|arithmeticexpr]
[% ... OR THRU|TO &variable|literal|arithmeticexpr]
           statementblock
[% END]

Parameters:

condition Can be a number or variable, followed by a space and a relational operator, followed by a space and a value. To specify multiple conditions, use the Boolean operators AND or OR with no parentheses.

Relational operator can be =, NOT =, <, >, NOT <, NOT >, <=, >=.

Value can be a number, a literal enclosed in apostrophes or quotation marks, or a variable.

statementblock Can contain any Customizer, COBOL, or S-COBOL statements.
variable Customizer variable with a valid COBOL name.

Processing:

During processing:

  • Customizer moves % REPEAT statement blocks to the starting columns of their controlling % REPEAT statements.
  • The statement block subordinate to the % REPEAT, and any statement block subordinate to the % UNTIL or % WHILE, establish the loop. The loop executes until or while the condition is satisfied.
  • In formats 1 and 2, if the % UNTIL or % WHILE does not have a subordinate statement block, AMB tests the condition and does the following:
    • If the % UNTIL condition is false or the % WHILE condition is true, the loop executes the % REPEAT statement block until the condition is true or while the condition is false, respectively.
    • If the % UNTIL condition is true or the % WHILE condition is false, the loop ends, and processing resumes at the next line that has the same or less indentation as the % UNTIL or % WHILE.
  • In formats 1 and 2, if the % UNTIL does have a subordinate statement block, AMB tests the condition and does the following:
    • If the % UNTIL condition is false or the % WHILE condition is true, the loop executes the % UNTIL or % WHILE statement block and the % REPEAT statement block until the condition is true or while the condition is false, respectively.
    • If the % UNTIL condition is true or the % WHILE condition is false, the loop ends without executing the % UNTIL or % WHILE statement block, and processing resumes at the next line that has the same or less indentation as the % UNTIL or % WHILE.
  • In format 3, with the TO option, the loop executes to--but not including--its specified variable, literal, or arithmetic expression.

Comments:

  • AMB evaluates any evaluation bracket source in an % UNTIL or % WHILE statementblock at each iteration of the loop; AMB evaluates bracketed source in a % REPEAT or % REPEAT VARYING call just once.
  • If FROM is not coded, the default is the current value of the % REPEAT &variable.
  • If BY is not coded, the default is BY 1.
  • AMB provides an internal loop counter, LOOP-LIMIT, which defaults to 500. To override the default, change the value of % SET LOOP-LIMIT in the AMB CNTL file APSDBDC. You can override the default with a number as high as 999999. Because some AMB libraries reset LOOP-LIMIT to 200, you might need to reset the limit after an % INCLUDE statement.
Previous Topic Next topic Print topic