Developer Documentation Library > Scripting > mrScriptBasic overview > mrScriptBasic language reference > Statements > Object collection iteration
 
Object collection iteration
An index syntax for repeating a statement, or assignment for each object in a collection.
Syntax
object[.. <options>].method
object[.. <options>].property = expression
<options> ::= [In categories]
Arguments
object
Collection object to iterate over.
categories
An expression that returns a categorical value.
method
A method or function to call on each element on the collection.
property
A property to set on each element in the collection.
Remarks
Object collection iteration provides a more concise syntax for iterating over an object collection.
The In clause makes it possible to specify a categorical value that specifies which indexes to use.
Examples: Data Management
The following example illustrates using the object collection iteration syntax in a DataManagementScript (DMS) file data cleaning routine. The example calls the Validation.Validate method for all of the question objects that are included in the data transformation.
Job.Questions[..].Validation.Validate(ValidateTypes.mrAssignDefault)
Here is another example that calls the Validation.Validate method for the iterations of a grid question called rating. The iterations of the grid are sometimes referred to as subquestions.
rating[..].Column.Validation.Validate(ValidateTypes.mrAssignDefault)
This example assumes that the grid is available to mrScriptBasic in the OnNextCase Event section as a Question object called rating. This would require including two or more of the variable instances that belong to the grid in the select query in the InputDataSource section of the DataManagementScript (DMS) file. (You cannot specify the grid itself in the select query, only the variable instances that belong to the grid. In this grid there is one variable instance for each iteration of the grid.) For example:
SelectQuery = SELECT rating[{Fossils}].Column, rating[{Birds}].Column FROM vdata
See Data Management Script (DMS) file for more information.
Example: UNICOM Intelligence Interviewer
The following example illustrates how you can use the object collection iteration syntax when you are defining the routing context of an interview script that will be activated in UNICOM Intelligence Interviewer:
' Ask the respondent each question in the loop

' Ask based on the answers from a previous question
Rating[..In WinesTasted].Ask()

' Pre-assign response values
Rating[..] = {Average}
See also
Statements