Desktop User Guides > Professional > Interview scripting > Writing interview scripts > Repeated questions > Numeric loops
Numeric loops
Use a numeric loop when you want to repeat one or more questions a fixed number of times, and the number of repetitions can be specified as a number or a range of numbers.
Use unbounded loops when you want to allow the respondent or interviewer to keep adding the required number of iterations. For more information, see Unbounded loops.
Metadata syntax for numeric loops:
LoopName loop [NumExpr] fields
) expand;
The name of the loop.
A numeric expression that determines how many times the questions in the loop should be asked.
The questions you want to ask.
This example asks the respondent to choose three insurance companies. Because the question is asked three times you will know the order in which the respondent chose the companies:
InsuranceCompanies define
RedWhiteBlue "Red, White, Blue Insurance",
InsuranceToGo "Insurance To Go",
WhistleHope "Whistle and Hope",
BestDeals "Best Deals",
CloverBenCo "Clover Ben and Co"
InsuranceCompany "Insurance companies to try"
loop [1..3] fields
WhichCompany "Which company will you try {number}?" categorical [1..1]
use InsuranceCompanies,
OtherCompany "Another company" other
) expand;
The routing section contains the following code to set the value of the number insert to first, second, or third according to the repetition.
Dim iteration, icomp
iteration= 0
For Each icomp in InsuranceCompany
iteration= iteration + 1
if iteration= 1 then
icomp.WhichCompany.Label.Inserts["number"].Text = "first"
elseif iteration= 2 then
icomp.WhichCompany.Label.Inserts["number"].Text = "second"
icomp.WhichCompany.Label.Inserts["number"].Text = "third"
end if
There are many ways in which you can specify the number of repetitions required. For example, you can repeat questions for all values in a range or only for selected values. You can set the start and end values in the range as part of the loop specification, or you can specify just an end value so that the start value varies according to the content of the current interview. The table shows examples of all the variations you can use.
Repeat for
Single values
[100, 200, 500]
100, 200 and 500 only. Real numbers do not work in loop control lists. If you want to use real values use a categorical loop instead.
A range of values
All whole numbers between 1 and 10 inclusive.
Several different ranges
[24..30, 50..60]
All whole numbers between 24 and 30 inclusive and between 50 and 60 inclusive.
Exclusive values
[1..10, ^5..7]
All whole numbers between 1 and 10 inclusive, except the whole numbers between 5 and 7 inclusive. (In other words, 1, 2, 3, 4, 8, 9, 10.)
Stepped values
[6..30 step 2]
All whole numbers between 6 and 30 inclusive in steps of 2. (In other words, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30.)
From undefined minimum to fixed maximum
Whole numbers less than 11, including negative numbers. The start point is set independently for each interview.
Has a fixed starting point and an undefined endpoint (an unbounded loop)
Whose number can be 1,2,3… and so on.
Has an undefined starting point and an undefined endpoint (an unbounded loop)
Whose number can be 1,2,3… and so on.
Here is a numeric loop that asks respondents how much their car insurance was in each of three different years and how they paid it. Notice how the example uses {@Year} to represent the current value of the loop control variable (Year) in the question text.
YearLoop "" loop [2005, 2006, 2007] fields
CarInsuranceCost "Approximately how much did you pay for car
insurance in {@YearLoop}?" long [1 .. 9999];
CarHowPaid "And which payment method did you use in {@YearLoop}?"
categorical [1..1]
CreditCardSingle "Single payment on credit card",
CreditCardSeveral "Several payments on credit card",
ChequeSingle "Single cheque payment",
ChequePostDated "A number of post-dated cheques",
OtherPaymentMethod "Other (specify)" other
) expand;
If you present the questions as a loop, the two questions are displayed one after the other on the same page for each repetition:
This graphic is described in the surrounding text.
See Asking repeated questions for information on how to display each question on a separate page.
If you present the questions as a grid, the questions for each repetition are displayed side by side with a separate page for each repetition. The following illustration shows that the layout for this example is not particularly pleasing for the Other category, so you might prefer to use a different layout for questions with this type of response.
This graphic is described in the surrounding text.
You cannot use real (decimal) numbers in the loop control list. If you want to write a loop based on real values, use a categorical loop (see Categorical loops) and specify the values as texts. A typical example of a repeated question based on a list of real values is one in which respondents are asked how likely they would be to purchase a product at various prices.
See also
Repeated questions