Home > Uncategorized > How To Set the order of Iteration within a Loop

## How To Set the order of Iteration within a Loop

Overview

This How-To will explain and show how you can set the order of iterations within a given loop chapter in a few simple steps:

2. Add the relevant code to the Call-Back function in order to perform your logical script.

Step 1:

function OnCreateIterationOrder(inChapterIndex, inIterationOrder)

{

} This function is called, behind the scenes, every time a chapter is entered (while conducting a survey).
the 1st parameter, ‘inChapterIndex’ passes through the current chapters index that the surveyor is located, for example: And the 2nd parameter, ‘inIterationOrder’ passes through the original iteration order of the loop, for example:
If chapter 1 is a loop that iterates 5 times, it will pass through: [1,2,3,4,5].

Step 2:

Lets say for example, that we have 2 chapters and chapter 2 is a loop that iterates 5 times according to an answer scale.
We want chapter two to iterate in the order [2,1,3,4,5], if Q1 (for example, a question in chapter 1) answer is equal to 2, we can write something like this:

function OnCreateIterationOrder(inChapterIndex, inIterationOrder)

{

if(inChapterIndex==2)

{

{

return [2,1,3,4,5];

}

else

{

return inIterationOrder;

}

}

}

* this should be written in the function we wrote in Step 1, within the advanced scripts box, as following: Basically, what I wrote is:
** If I am in chapter index 2 -> check if the answer of Q1 is 2
-> if it is answer 2 -> set the iteration order to be [2,1,3,4,5];
elsewhere (Answer is not 2) -> set the iteration order to be the original one.
**

You can write any script that you wish in order set different loop iterations order with this method.

That’s it!

Categories: Uncategorized