Professional > Interview scripting > Writing interview scripts > Filtering questions and response lists > Filtering loops > Random filtering for loops > Repeat a loop once for a randomly selected value
 
Repeat a loop once for a randomly selected value
With this method, the loop is defined with a randomized control list so that the routing section does not have to bother about reordering the control list before selecting a value. The example asks members of the product development group about one project that their group has worked on (it assumes that all members of the team have worked on all projects). The project is chosen from a randomized list of projects tackled during the year.
The same questions are asked for each project, so they are defined in a loop whose control list contains the project descriptions:
Projects loop
{Project1, Project2, Project3, Project4} ran
fields
(
Position "What was your position in the {@Projects} project team?"
categorical [1..1]
{
Designer, Developer, Writer, QA, Manager
};
HowLong "How long (in months) did you work on this project?"
long [1..12];
Likes "What did you particularly enjoy about this project?"
text;
Dislikes "And was there anything you disliked about the project?"
text;
) expand;
The routing section needs to select one project from the list and ask just that iteration of the loop. There are a number of ways you can do this, but the most efficient is as follows:
Projects[Projects.DefinedCategories().Ran(1)].Ask()
It tells the interviewing program to select at random one category from the Projects category list and to ask the questions in the loop for just that category. All questions in the loop will be displayed on the same page.
See also
Random filtering for loops