Scripting > mrScriptMetadata User's Guide > mrScriptMetadata reference > Field definitions > Numeric loop
 
Numeric loop
A loop defines a set of questions that are to be asked more than once. In a numeric loop, the number of times the loop is to be repeated (and therefore the number of times that the set of questions in the loop are to be asked) is controlled by a numeric range expression. In technical terms, a numeric loop is an array of questions in which the index into the array is based on a numeric range expression.
The way in which the loop is asked will determine how the question is presented. If the loop is asked as a single question, then a grid presentation can be used. If the interviewing mode does not support grid presentation, then the iterations of the loop can be asked separately.
Syntax
For clarity, each item is shown on a separate line, and optional items are indented, See also Syntax conventions.
field_name
  [ "field_label" ]
  [ [ <properties> ] ]
  [ <styles and templates> ]
loop
[
range_expression ]
fields
  [ "iteration_label" ]
( <field> (; <field> )* [;] )
  [ row | column ]
  [ expand ]
  [ grid ]
Parameters
field_name, field_label
See Names and labels for more information.
<properties>
You can define custom properties for your field to store information that is not directly supported by the Metadata Model (MDM). See Custom properties for more information.
<styles and templates>
You can use styles and templates to define the appearance of a question. See Styles and templates for more information.
range_expression
To specify
Syntax
A range of values
Field loop [ n1 .. n2 ]
 
Example:
Visits loop [1..10]
 
The loop repeats 10 times (once for each value in the range).
several different ranges
Field loop [ n1 .. n2 , n3 .. n4 , n5 .. n6 ...]
 
Example:
Rate loop [24..56, 100..1000]
 
The loop repeats 934 times (once for each number within each range).
single values
(Not supported in Data Model 2.8.)
Field loop [ n1 , n2 , n3 , n4 ...]
 
Example:
Sizes loop [100, 200, 500]
 
The loop repeats three times (once for each value that is specified).
a minimum to undefined maximum
Field loop [ n1 ..]
 
Example:
People loop [1..]
 
The number of times the loop repeats is undefined and will be decided when each interview takes place. This is sometimes called an unbounded loop. For example, in a household survey, the loop will be repeated once for each person in the household. However, this loop definition is supported only when the data is being stored hierarchically and you cannot use the expand keyword on a loop that has an undefined maximum number of iterations.
from undefined minimum to maximum
Field loop [.. n1 ]
 
Example:
Cars loop [..10]
 
The loop repeats up to ten times, depending on the start value, which will be decided when each interview takes place.
exclusive values
Field loop [^ n1 .. n2 ]
 
Example:
Grade loop [1..10, ^5..7]
 
The loop repeats 7 times, once for each whole number between 1 and 10 inclusive, except the whole numbers between 5 and 7 inclusive (that is, 1, 2, 3, 4, 8, 9, 10).
stepped values
Field loop [ n1 .. n2 step n3 ]
 
Example:
mount loop [0..100 step 10]
 
The loop repeats 11 times, once for all whole numbers between 0 and 100 inclusive in steps of 10 (that is, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100.)
iteration_label
Defines a label that will be displayed for each iteration when the questions in the loop are asked sequentially. For more information about labels, see the description for field_label in Field definitions. To include the current number from the loop's range expression in the label, use an index insertion: see Label text insertion.
<field>
Defines a question inside the loop. See Field definitions for more information.
row
Specifies that the iterations are to be displayed as rows when the loop is displayed as a grid. Note that this is the default behavior if neither the row or column keywords are specified.
column
Specifies that the iterations are to be displayed as columns when the loop is displayed as a grid.
expand
The UNICOM Intelligence Data Model can represent the case (response) data collected using a loop in a “flattened” format, a hierarchical format, or in both formats. Which format is used depends on how you define the loop and the format in which the case data is being stored (because the capabilities of the various CDSCs vary). By default, loops are defined as levels, which means that the case data is stored in a hierarchical format only. However, you can use the expand keyword to specify that it should be stored in a flattened format. For example, you would need to do this if the case data is being stored in an SPSS .sav file, because the SPSS SAV DSC does not support a hierarchical view of the data. If the DSC supports both a hierarchical and a flattened view of the data (such as RDB DSC 2 does), using the expand keyword means that the data is represented in both formats, provided the loop is not nested within another loop.
For more information about hierarchical data, see Hierarchical data in the MDM.
grid
Defines that the loop is to be displayed as a grid question. However, you must make sure that the loop is suitable for display as a grid question: it must contain only simple questions and not any nested loops, blocks, or compounds.
Make sure that you specify the grid keyword if you want UNICOM Intelligence applications and components to recognize that the loop is a grid. Some UNICOM Intelligence tools treat a grid differently from a loop that is not a grid.
Remarks
For more information about writing numeric loops in interview scripts, see Numeric loops.
Example
This example declares a simple numeric loop that asks questions for each member of the household, up to a maximum of 10 household members.
Household "Household Questions" loop [1 .. 10] fields
(
Name "What is the person's name?" text [5 .. 30];
Gender "Male or Female?" categorical [1]
{
Male,
Female
};
) expand;
This illustration shows the loop asked as a single question in a grid presentation. (Its exact appearance depend on the mode of interviewing and the formatting options applied.)
See
Field definitions