Loops
Key Considerations
Loops are used for a series of repeating questions.
Loops are also used when grids have no overarching question text.
Loops are used for single-column grids.
The term ‘loop’ is used to describe a series of actions that are completed over and over until a certain condition becomes true.
“Place once slice of bread buttered side up, then add lettuce, two slices of cheese, and top with another slice of buttered bread, face down. Repeat this until you have four sandwiches.”
In DDI 3.2, a Loop is used when describing a series of repeating questions. They can include all types of constructs, including questions, conditions, sequences, and even other loops. The limit to how many times the question in the loop is repeated is set by a logic. This logic either draws on a source outside of the loop, such as a the question before the loop, or it is stated directly within the loop itself. This is explained in further detail with the examples below.
A loop construct contains the following components. Required: Label, Variable, and Start Value. Optional: End Value and Loop While.
The loop Label is created from the first question inside the loop, not the first item inside the loop.
Loop variables indicate why a series of questions are repeating (e.g., loop for every child in the household, loop for all your previous partners, loop for every physical health condition that you have). It has the format of _[variabletext]. Loop variables must be singular and lowercase without spaces. For example, if the questions are repeating for every person in the household, the loop variable would be _householdmember, rather than _HouseholdMembers. The text should be short and unique. For instance, if there are several loops in a questionnaire about children of different age groups, the variable should reflect this (e.g., _child05, _child15).
The start value is always 1 because every loop runs at least once.
End values and loop whiles represent the maximum number of times a loop can run. This can be a fixed maximum number of times defined by logic based on the response to a question (End Value), questions (Loop While), or a combination of the two. If an end value is not defined in the questionnaire, then the end value and loop while fields are left blank. Loop while logic looks very similar to condition logic. However, unlike in condition logic, quotation marks are never used to indicate a specific number or text answer.
Example 1
When a loop relies on the answer to a previous question, such as how many times something has occurred, the logic used to generate the loop references the question.
Questionnaire: Next Steps Age 14 Survey (2004)
Questionnaire layout:
Archivist Build / Constructs:
Archivist view (ns_04_w1):
In Example 1 above, the loop l_qNRSname references question qc_NresSib in the first part of the logic to begin the loop cycle. This runs as many times as the number that the respondent provides for the question ‘Can I just check, does … have any older brothers or sisters who are not currently living here with you?…’.
_nonresidentoldersibling from 1 while _nonresidentoldersibling <= 15 && <= qcNresSib
Note that the loop variable is singular (i.e., _nonresidentoldersibling rather than _nonresidentoldersiblings).
The part of the logic <= 15 tells us that the cycle must not run more than 15 times, as the maximum number of siblings the respondent could have reported in question qc_NresSib is 15.
Note that the number 15 does not have quotation marks around it - unlike in condition logic, quotation marks are never used in loop logic.
Example 2
Sometimes a loop is used when we cannot use a Question Grid because the series of questions has no overarching text, which is an essential part of a question grid.
In this example, a Loop While has been added because there are five blank rows in the questionnaire, which indicates that the respondent can answer the series of questions up to five times. An End Value is not needed in this case.
Questionnaire: National Survey of Health and Development 1963 Follow Up of 1963 School-Leavers
Questionnaire layout:
Archivist Build / Constructs:
Archivist view (nshd_63_yeoq):
Conditions that control who enters the loop
As outlined in the Conditions page, conditions are constructs that determine who answers a question(s based on their response to a previous question(s). When a condition is the first construct inside a loop, and that condition determines whether the respondent enters the loop or not, the condition should be moved before the loop.
In Example 3, although in the PDF the condition is the first construct inside the loop, in Archivist, the condition is entered before the loop, as it controls who enters the loop.
Example 3
Questionnaire: BCS70 Age 34 Follow up CAPI Questionnaire (bcs_04_capi)
Questionnaire layout:
Archivist build (bcs_04_capi)
Archivist view (bcs_04_capi)