Desktop User Guides > Professional > Interview scripting > Writing interview scripts > Filtering questions and response lists > Filtering loops > Filtering the repetitions of loops with numeric control lists
 
Filtering the repetitions of loops with numeric control lists
You can filter the repetitions of loops with numeric loop control lists using the response to a long type numeric question. For example, you can filter a loop so that it is repeated for every member of the household rather than the maximum number of people you have allowed per household. When you filter based on the answer to a numeric question, the interviewing program treats the response as ā€œ1..responseā€ because you normally want to ask on the first ā€œnā€ repetitions. For example, if the metadata is
PeopleInHousehold "How many people are there in your household?"
long[1..9];
PersonLoop loop [1..9]
fields
(
PersonAge "How old is person {@PersonLoop}?" long [0..99];
PersonGender "Is this person ...?" categorical [1..1]
{Male, Female}
) expand;
the routing statements to repeat the loop for just the number of people in each household will be:
PeopleInHousehold.Ask()
PersonLoop.QuestionFilter = PeopleInHousehold
PersonLoop[..].Ask()
The [..] notation in the last statement causes each iteration of the loop to be presented as a separate page rather than as a grid all on one page. If there are three people in the household, the respondent will see three pages only even though the loop is defined to execute a maximum of nine times. A typical page looks like this:
Filtering for a numeric grid with each iteration asked separately
This graphic is described in the surrounding text.
If you would prefer to use a grid, define the loop as:
PersonLoop1 "For each person in the household ..." loop [1..9]
fields
(
PersonAge1 "Age" long [0..99];
PersonGender1 "Gender" categorical [1..1]
{Male, Female}
) grid expand;
and write the .Ask statement as:
PersonLoop1.QuestionFilter = PeopleInHousehold
PersonLoop1.Ask()
The page then becomes:
This graphic is described in the surrounding text.
See also
Filtering loops