NIPO ODIN Version 5.17

Previous Topic

Next Topic

Repeat Number

The operator ?R contains the current value of a *REPEAT loop, a number between and including 1 and n where n is the value specified at the *REPEAT statement. Note that this is not the iteration number - for example, in the third execution in the loop the value of ?R is not necessarily 3. This is especially true for randomized, controlled, rotated or inverted loops.

In nested blocks, the operator ?R returns the value of the loop where is nested in. To access values from loops above or below the current, you should use a question or a numerical variable to pass the value. The operator does not exist outside the scope of a *REPEAT block.

?R is a system variable and can not be changed (for example by using *SAVE or *PUT) nor can it be displayed directly in question text using the *? command. Copy the value to a variable another variable to access it (e.g. *PUT Temp [?R]).

Example using the repeat number

*TEXTVARS paper
*QUESTION 2 *CODES 61L7 *MULTI

Which of the following newspapers do you know?

1: La Repubblica
2: La Stanza
3: The Mirror
4: The New York Times
5: Le Figaro
6: La Libération
7: None *NMUL

*REPEAT 6 *FIELD 68L12 *CONTROL Q2 W
*PUT paper Q2,?R
*QUESTION 3 *CODES 1

How often do you read *? paper?

1: Daily
2: Once a week
3: Once a month
4: Don’t know

*ENDREP

In nested blocks you have to transfer the repeat number ?R of the outer block to a numeric variable first to be able to use it in the inner block.

Example storing the repeat value

*VARS X,Y,Z
*REPEAT 3
*PUT X [?R]
*REPEAT 2
*PUT Y [?R] ** this line is only necessary to display the value of ?R
*PUT Z [X+?R] ** or *PUT Z [X+Y]
*QUESTION 1

*?X + *?Y = *?Z

*ENDREP
*ENDREP

See Also