Professional > Interview scripting > Writing interview scripts > Filtering questions and response lists > Filtering loops > Filtering the repetitions of loops with categorical control lists
 
Filtering the repetitions of loops with categorical control lists
Filtering the repetitions of a loop with a categorical control list is similar to filtering an ordinary categorical response list. You define the loop so that its control list contains all possible categories, and then add routing statements that specify for which categories the loop should be executed.
Syntax
In the routing section, type:
Name.Categories.Filter = {Category_Spec}
Parameters
Name
The name of the loop.
Category_Spec
The categories to be displayed. This may be the name of a single category or a comma-separated list of category names, both enclosed in curly braces. Alternatively, you can specify a range of categories using the standard range syntax: see Category expressions.
Parameters
Here is an example based on a loop that is defined in the metadata section as follows:
FoodList define
{
Fruit, Vegetables, Salads, Fish, Meat, Bread,
Dairy "Dairy produce",
Pulses "Pulses/Nuts/Cereals",
PastaRice "Pasta/Rice"
};
TimesEaten "On the following days last week, how many times did you
eat ... ?" loop
{use FoodList}
fields
(
Monday long [0..10];
Tuesday long [0..10];
Wednesday long [0..10];
Thursday long [0..10];
Friday long [0..10];
Saturday long [0..10];
Sunday long [0..10];
) grid expand;
We want to ask about pulses/nuts/cereals, pasta/rice and bread only. We do this by placing the following statement in the routing section before we ask the loop:
TimesEaten.Categories.Filter = {Pulses, PastaRice, Bread}
TimesEaten.Ask()
If the categories to be used as filters are defined consecutively, you can save yourself work by using the double-dot range operator. For example:
TimesEaten.Categories.Filter = "Fruit..Bread"
Another way of filtering loop repetitions is to use the QuestionFilter object with a simple reference to the loop name:
TimesEaten.QuestionFilter = {Fruit, Salads}
This produces a grid with rows for fruit and salads only and columns for all days of the week. Because there is no [..] qualifier specified for the loop name (TimesEaten), the interviewing program assumes that the filter applies to the repetitions of the loop rather than the questions.
See also
Filtering loops