Loops

Key Considerations

  • Loops are used for a series of repeating questions
  • Loops are also used when grids have no over-arching question texts.
  • 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 useful when describing a series of repeating questions (see https://ddialliance.github.io/ddimodel-web/DDI-L-3.2/item-types/Loop/). They can include all types of constructs, including question grids, conditions, sequences, and even other loops. The limit to how many times the question is repeated per instance is set by a logic (a mathematical representation of a decision point, where different choices route the participants in different ways). This logic either draws on a source outside of the loop, such as a previous question, or it is stated directly within the loop itself. This is explained in further detail with the two 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.

Loops 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 input in lower case 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 loops in a questionnaire about children of different age groups then 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 both 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 in loop logic.

Example 1 Questionnaire: Understanding Society COVID-19 Wave 2 Questionnaire

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 layout:

Archivist Build / Constructs (us_covid_q2):

Archivist view (us_covid_q2):

In Example 1 above, the loop l_qpersonsex references question qc_hhnum 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 ‘Including yourself, how many people are currently living in your household? Please include everyone, even if it is only a temporary arrangement.?’:

 _householdmember from 1 while _householdmember <= qc_hhnum && _householdmember <= 25

  • Note that the loop variable is singular (i.e., _householdmember rather than _householdmembers). Loop variables should always be singular.

In the second part of the logic, the <= 25 tells us that the cycle must not run more than 25 times, as there are only 25 spaces to record a household member shown in the original document.

_householdmember from 1 while _householdmember <= qc_hhnum &&_householdmember <= 25)

  • Note that the number 25 does not have quotation marks around it. Unlike in condition logic, quotation marks are never used in loop logic.

Example 2 Questionnaire: National Survey of Health and Development 1963 Follow Up of 1963 School-Leavers

Sometimes a loop is used when we cannot use a Question Grid because the series of questions has no overarching text - an essential part of a question grid. In this example, a Start Value and a Loop While have 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 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). In the event that a condition is the first construct inside a loop, and 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)