LOOP Examples

Example 1: Increment Variable name and Variable value

LOOP 8,A=A(1),B=1(1)

IF Q2$A (1-3) ASSIGN Q3A = ($B)

ENDLOOP

These LOOP/ENDLOOP commands would be the equivalent of the following Glossary statements:

IF Q2A (1-3) ASSIGN Q3A = (1)

IF Q2B (1-3) ASSIGN Q3A = (2)

IF Q2C (1-3) ASSIGN Q3A = (3)

IF Q2D (1-3) ASSIGN Q3A = (4)

IF Q2E (1-3) ASSIGN Q3A = (5)

IF Q2F (1-3) ASSIGN Q3A = (6)

IF Q2G (1-3) ASSIGN Q3A = (7)

IF Q2H (1-3) ASSIGN Q3A = (8)

For example, the variable Q2A is incremented to Q2B, Q2C, etc. The variable value of Q3A = (1) is incremented to Q3A = (2), Q3A = (3), etc.

Example 2: Increment Variable name and Variable value

LOOP 10,A=1(2),B=QA(1)

  IF $B1_$A (1-10) COMPUTE $B1_$A = 11 - $B1_$A

  ASSIGN $B$A = ($A)

ENDLOOP

These LOOP/ENDLOOP commands would be the equivalent of the following Glossary statements:

IF QA1_1 (1-10) COMPUTE QA1_1 = 11 - QA1_1

ASSIGN QA1 = (1)

IF QB1_3 (1-10) COMPUTE QB1_3 = 11 - QB1_3

ASSIGN QB3 = (3)

IF QC1_5 (1-10) COMPUTE QC1_5 = 11 - QC1_5

ASSIGN QC5 = (5)

IF QD1_7 (1-10) COMPUTE QD1_7 = 11 - QD1_7

ASSIGN QD7 = (7)

IF QE1_9 (1-10) COMPUTE QE1_9 = 11 - QE1_9

ASSIGN QE9 = (9)

IF QF1_11 (1-10) COMPUTE QF1_11 = 11 - QF1_11

ASSIGN QF11 = (11)

IF QG1_13 (1-10) COMPUTE QG1_13 = 11 - QG1_13

ASSIGN QG13 = (13)

IF QH1_15 (1-10) COMPUTE QH1_15 = 11 - QH1_15

ASSIGN QH15 = (15)

IF QI1_17 (1-10) COMPUTE QI1_17 = 11 - QI1_17

ASSIGN QI17 = (17)

IF QJ1_19 (1-10) COMPUTE QJ1_19 = 11 - QJ1_19

ASSIGN QJ19 = (19)

For example, the variable QA1_1 is incremented to QB1_3, QC1_5, etc. The variable value of QA1 = (1) is incremented to QB3 = (3), QC5 = (5), etc.

 

Example 3: Specify the starting Variable name, increment and number of times to execute the loop

LOOP 10,A=QT1_1 (1)

IF $A ( ) ASSIGN $A = (0)

ENDLOOP

These LOOP/ENDLOOP commands would be the equivalent of the following Glossary statements:

IF QT1_1 ( ) ASSIGN QT1_1 = (0)

IF QT1_2 ( ) ASSIGN QT1_2 = (0)

IF QT1_3 ( ) ASSIGN QT1_3 = (0)

IF QT1_4 ( ) ASSIGN QT1_4 = (0)

IF QT1_5 ( ) ASSIGN QT1_5 = (0)

IF QT1_6 ( ) ASSIGN QT1_6 = (0)

IF QT1_7 ( ) ASSIGN QT1_7 = (0)

IF QT1_8 ( ) ASSIGN QT1_8 = (0)

IF QT1_9 ( ) ASSIGN QT1_9 = (0)

IF QT1_10 ( ) ASSIGN QT1_10 = (0)

For example, the variable QT1_1 is incremented to QT1_2, QT1_3, etc. because the increment value is (1). If the increment value was (2), it would skip from variable QT1_1 to QT1_3.

 

Example 4: Use variables defined in the Glossary in Glossary looping logic

 

 ADDLEN 1000

 

 DECLARE Q5_1,Q5_2,Q5_3,Q5_4,Q5_5,Q5_6,Q5_7,Q5_8,Q5_9,Q5_10

 

 LOOP 10,A=Q6_1(1),B=1(1)

 IF $A (1) ASSIGN Q5_$B = (1)

 ENDLOOP

These LOOP/ENDLOOP commands would be the equivalent of the following Glossary statements:

IF Q6_1 (1 ) ASSIGN Q5_1 = (1)

IF Q6_2 (1 ) ASSIGN Q5_2 = (1)

IF Q6_3 (1 ) ASSIGN Q5_3 = (1)

IF Q6_4 (1 ) ASSIGN Q5_4 = (1)

IF Q6_5 (1 ) ASSIGN Q5_5 = (1)

IF Q6_6 (1 ) ASSIGN Q5_6 = (1)

IF Q6_7 (1 ) ASSIGN Q5_7 = (1)

IF Q6_8 (1 ) ASSIGN Q5_8 = (1)

IF Q6_9 (1 ) ASSIGN Q5_9 = (1)

IF Q6_10 (1 ) ASSIGN Q5_10 = (1)

For example, the variable Q6_1 is incremented to Q6_2, Q6_3, etc. because the increment value is (1). The variable Q5_1 is incremented to Q5_2, Q5_3, etc. because the increment value is (1).

 

Example 5: Use variables defined inside the Glossary looping logic

 

 ADDLEN 10000

 

 LOOP 9,A=1(1),B=10(3)

 DECLARE AGE_YEARS_$A = 1/100$B:3

 DECLARE AGE_MONTHS_$A = 1/101$B:3

 ENDLOOP

These LOOP/ENDLOOP commands would be the equivalent of the following Glossary statements:

DECLARE AGE_YEARS_1 = 1/10010:3

DECLARE AGE_MONTHS_1 = 1/10110:3

DECLARE AGE_YEARS_2 = 1/10013:3

DECLARE AGE_MONTHS_2 = 1/10113:3

DECLARE AGE_YEARS_3 = 1/10016:33

DECLARE AGE_MONTHS_3 = 1/10116:3

DECLARE AGE_YEARS_4 = 1/10019:3

DECLARE AGE_MONTHS_4 = 1/10119:3

DECLARE AGE_YEARS_5 = 1/10022:3

DECLARE AGE_MONTHS_5 = 1/10122:3

DECLARE AGE_YEARS_6 = 1/10025:3

DECLARE AGE_MONTHS_6 = 1/10125:3

DECLARE AGE_YEARS_7 = 1/10028:3

DECLARE AGE_MONTHS_7 = 1/10128:3

DECLARE AGE_YEARS_8 = 1/10031:3

DECLARE AGE_MONTHS_8 = 1/10131:3

DECLARE AGE_YEARS_9 = 1/10034:3

DECLARE AGE_MONTHS_9 = 1/10134:3

For example, the variable AGE_YEARS_1 is incremented to AGE_YEARS_2, AGE_YEARS_3, etc. because the increment value is (1). The variable AGE_MONTHS_1 is incremented to AGE_MONTHS_2, AGE_MONTHS_3, etc. because the increment value is (1). The record/location:width of 1/10010:3 is incremented to 1/10013:3, 1/10016:3, etc. because the increment value is (3). The record/location:width of 10110:3 is incremented to 1/10113:3, 1/10116:3, etc. because the increment value is 3.

Related topics:

Looping logic