Home > Uncategorized > How To Implement Nested Loops

How To Implement Nested Loops

Overview

 

In many of the surveys there will be a need to repeat a certain question (or group of questions) for many different Topics. For example if you mention certain brands you are aware fo then ask few questions (same ones) on each brand. SurveyToGo enables the easy creation of such scenarios without the need to duplicate the repeating part code in the script.

This is done using loop chapters as explained here.

In some specific scenarios there will be a need to have the repeating parts in more than one level i.e as nested loops. Nested loops are a group of individual loops; each is nested within the other, sharing combined values and logic. SurveyToGo fully supports the implementation of such scenarios as nested loops

 

Pricing Note: The SurveyToGo Nested Loops feature comes at a monthly charge (unlimited use) to our pay-per-interview customers, and is included free of charge for SurveyToGo Subscription customers. Request your 7 days free trial today by contacting support@dooblo.com.

To sign up for the SurveyToGo Nested Loops, please see this link: https://www.dooblo.net/stgi/order.aspx?sku=3216010

 

Basic terminology/concepts with nested loops

 

  • Nested loop (except for the most outer loop chapter / first loop chapter) is a sub-chapter of the loop chapter above it. So for instance, as you can see in the below screen shot, if chapter “Loop 2” is nested in chapter “Loop 1”, then “Loop 1” is considered as the “parent” of “Loop 2”:

     

  • Each chapter in a nested loops chapters structure has a “level index”, starting from the most inner loop, all the way up to the outer loop. For example, in the below screen shot, from “Loop 3” point of view, its level is 0, its “parent” loop level (which is “Loop 2”) is 1, and its “grandparent” loop level (which is “Loop 1”) is 2.

    Yet from “Loop 2” point of view, its own level is 0, and its “parent” loop level (“Loop 1”) is 1.

     

 

Most common nested loops functions

 

It is important to note that each iteration has its own execution order so in a given time during run time we may be at the (for example) 2rd iteration of the outer loop, the 3rd iteration of the first inner loop and the 1st iteration of the second inner loop (can be represented as iteration 2-3-1 for example). The following functions refer to referencing the Iteration sequence.

GetParentIterationIndex(int level): Gets a loop chapter’s level and returns its current iteration index.

Example: Loop A is the parent of Loop B. I’m currently inside a question in loop B. The current iterations state is: Loop A is in its second iteration, and loop B is in its fifth iteration.

I want to pipe the text of the selected answer in Q2 that is in loop A, inside the text of the question I’m in currently (in loop B).

So, I’ll put this code in the “loop b” question’s start script:

SetTextFormat(CurrQues, SelectedAnswerTextIter(QRef(2),GetParentIterationIndex(1));

(“Loop A” is level 1 from “Loop B” point of view)

GetParentIterationName(int level): Gets a loop chapter’s level and returns its current iteration name (used exactly as is in GetParentIterationIndex()).

CreateMultiIterationsString(int[]
iterations
):
Gets a list of iteration indexes from all relevant loop chapters, and creates a indexes string to later use to pull values entered in a specific iterations state.

The list indexes order should be from the most outer loop to the most inner loop.

Example: In my survey I have 3 nested loops, “Loop C” that is nested in “Loop B” that is nested in “Loop A”. “Loop C” has a single choice question, Q10.

After completing the nested loops section, I want to pull the answer that was coded in Q10, while the iterations state was this: “Loop A” was in its fourth iteration, “Loop B” was in its second iteration, and “Loop C” was in its fourth iteration.

So, I’ll pull the value using this code:

AnswerIter(QRef(10), CreateMultiIterationsString(4, 2, 4));

 

For further information on SurveyToGo visit our support and knowledge portal at http://support.dooblo.net

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: