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

How To Set the order of Iteration within a Loop


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:

  1. Add the needed Call-Back function to the ‘Advanced Scripts’
  2. Add the relevant code to the Call-Back function in order to perform your logical script.

Step 1:

Add the following code to your advanced script’s box:
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:

Configure your function to suit your logical scripts.
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)






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




            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
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: