Data editing > Flow control > Loops > do with codes
 
do with codes
Quick reference
To repeat a set of statements for all codes in a given range, type:
do label 'variable' = 'code1','code2'
To repeat a set of statements for each of a given list of codes, type:
do label 'variable' = ('code1','code2', ... )
More information
You might need to repeat a statement or set of statements for a given set of codes, rather than for columns or other types of variable. To do this, write a do statement which, instead of naming an integer variable and whole numbers, defines a list of codes and a temporary variable which points to each code in turn. When you want to refer to the current code, enter the name of the temporary variable; Quantum substitutes the value of the current code in the statement before it is executed.
The format of a do statement for codes is:
do label.num ’var.name’ = ’p1’, ’p2’
to execute statements for all codes in the range ‘p1 to ‘p2, where the sequence of codes is &‑01234567890–&;
or:
do label.num ’var.name’ = (’p1’, ’p2’, ’p3’, ... )
to execute statements for the listed codes only.
In both formats, note that the variable name and the codes must all be enclosed in single quotes. Additionally, you can not use the notation ' ' to indicate a blank code, nor may you use the temporary variable in partial column moves (that is, in statements of the form c(1,4)=c(3,6)).
Example
This example checks for certain codes in a series of columns:
do 10 'code' = ('1','3','5')
if (c110'code' .or. c111'code') emit c180'code'
10 continue
This loop executes three times, once for each of the three listed codes. The first time the loop is executed, the statement reads:
if (c110'1' .or. c111'1') emit c180'1'
The second time it is:
if (c110'3' .or. c111'3') emit c180'3'
The third time it is:
if (c110'5' .or. c111'5') emit c180'5'
See also
Loops