Desktop User Guides > Professional > Interview scripting > Writing interview scripts > Repeated questions > Unbounded loops
 
Unbounded loops
You can script unbounded (also known as unexpanded) loops, where iterations can be added to a loop continually during an interview and the maximum number of iterations is undefined. These script loops iterate based on a previous numeric response with no maximum configured value. The scripts used to build unbounded loops can be rendered in the UNICOM Intelligence applications that support unbounded loops.
You can script an unbounded loop that enables the respondent, or interviewer, to continue adding the required number of iterations. A selection can be made to end the loop when the number of iterations is satisfied. When the loop is closed, an added iteration is essentially deleted. The following example provides a simple unbounded loop:
Person "Person" loop [1..] fields -
(
Name "Name" text;
Age "Age" categorical [1..1]
{
Young "Young",
Old "Old"
};
);
In this example, the unbounded loop does not include an expand keyword in the definition. The unbounded loop can be called with the following script:
' Ask questions for each person in the household
HowManyPeople.Ask()
Dim Index
For Index = 1 To HowManyPeople
  Person[Index].Ask()
Next
' An alternative method is to use the following if the Person
' loop is setup to use HowManyPeople as its Iteration control.
HowManyPeople.Ask()
Person.QuestionFilter = HowManyPeople
Person.Ask()

' Add a new person
Person[LoopIterations.New].Ask()
Configuring unbounded loops
Before an unbounded loop can be asked, the iterations related to it should be specified as in the following example:
person "Person" loop [..] fields -
(
trip "Trip" loop [..] fields -
(
DaysForStay "DaysForStay" long;
CountryName - text;
);
name "Name" text;
numberOfTrips "numberOfTrips" long;
);
You can specify the iterations via the property QuestionFilter (for example, Person.QuestionFilter = 3).
You can specify the iterations via the method Add. For example:
Set SinglePerson = person[LoopIterations.New]
In this example, person.count will be increased by one.
The number of iterations should be specified before an unbounded loop is asked; if the loop contains a nested unbounded loop, the number of iterations should also be specified before being asked.
Adding iterations to an unbounded loop
The following example can be used to add unbounded loop iterations:
person[LoopIterations.New].Ask()
Set SinglePerson = person[LoopIterations.New]
SinglePerson.Ask()
If the unbounded loop’s QuestionFilter is set (for example, to 3) before adding an iteration, the newly added iteration will have a levelID of 4. If the unbounded loop’s QuestionFilter is not set, the newly added iteration will have a levelID starting at 1.
The example .mdd file MeetingManagent-Enrollment.mdd demonstrates how to add unbounded loop iterations. It is installed with the UNICOM Intelligence Developer Documentation Library at:
[INSTALL_FOLDER]\IBM\SPSS\DataCollection\<version>\DDL\Scripts\Interview\Documentation
Removing iterations from a unbounded loop
The following example can be used to remove unbounded loop iterations. It deletes an iteration with a LevelID=1.
Person.delete (1)
The following example, deletes the iteration with an iteration name of _1.
Person.delete ("_1")
The example .mdd file MeetingManagent-EnrollmentPlus.mdd demonstrates how to remove unbounded loop iterations. It is installed with the UNICOM Intelligence Developer Documentation Library at:
[INSTALL_FOLDER]\IBM\SPSS\DataCollection\<version>\DDL\Scripts\Interview\Documentation
See also
Repeated questions