Home > Studio Manual > Chapter 14 – Programming Loops

Chapter 14 – Programming Loops

Back to Table Of Contents
Back to Chapter 13 – Survey Scores

Chapter 14 – Programming Loops

 

Overview

Loops are very helpful when programming surveys. Loops enable you to write a set of questions once and then display this set of questions for any number of times without having to “copy & paste” these questions. Loops are implemented in SurveyToGo as a property of a chapter. This means that once you configure the chapter to loop, all the questions inside this chapter will be displayed according to the loop settings.

How to make it happen

Configuring loops is very easy. Simply follow these steps:

  1. Add the questions you would like to loop, and make sure to put them under a chapter.
  2. Configure the loop options of the chapter.

Below you will find 2 examples of common looping scenarios and how to configure them:

  1. Example 1: Looping for X number of times according to a numeric question
  2. Example 2: Looping for X number of times according to a multi select question

Step 1: Add the questions you would like to loop

The first thing to do when working with loops is to add a chapter and then add all the questions you wish to include in the loop under that chapter. To add a chapter, either right click the Root Chapter and select “Add sub-chapter”:

c14-1

Or select the “Add chapter” from the toolbar menu:

c14-2

Then follow the regular procedure to add questions under that chapter. Please refer to earlier chapters in this manual to learn more about adding questions and chapters.

Step 2: Configure the loop options of the chapter

Once all the questions are in place, click on the chapter that contains them and select the “Loops” tab:

c14-3

The loop tab contains the following iteration options:

Option Description
No Iterations Do not loop this chapter
Iteration Maximum number of times Loop this chapter based on a maximum number of times
Iterate By scale Loop this chapter through the items present in a pre-configured scale – see Chapter 12 for scale reference
Include in Chapter Locator Include all the loops of this chapter in the chapter locator if the chapter locator is enabled.
Randomize Iterations Loop this chapter each time using a different order. Specifically useful when used with scales.
Use Iteration Entrance Rule Use an entrance rule when looping. If the entrance rule evaluates to false, the specific iteration will be skipped. By default this setting is false.
Print only one iteration When printing the survey using the “Survey > Print” action, print only the first iteration.

The tab also contains the following code sections:

Section Description
Iteration Break Rule If this expression is true, the loop will end.
Iteration Start Script This script will be run at the start of each iteration of the loop.
Iteration End script This script will be run at the end of each iteration of the loop.
Iteration Entrance Rule If the entrance rule evaluates to false, the specific iteration will be skipped.

Example 1: Looping for X number of times according to a numeric question

Let’s suppose we need to ask a certain set of questions for each room in an apartment. In this case we will first ask how many rooms there are in the apartment, and then loop through the per-room questions for the number of times necessary.

To perform this example we will do the following:

  1. Add the numeric “how many rooms” question + add the chapter with the “per-room” questions.
  2. Configure the looping.

Step 1: Add the numeric “how many rooms” question.

c14-4

Step 2: Configure the looping

We will assume there are a maximum of 8 rooms in the apartment and will there for set the “Maximum Iterations” to 8:

c14-5

We will then configure the break rule to stop the rule when we hit the number of rooms that was specified in Q1:

c14-6

Note the use of the new “IterationIndex” value that specifies the current iteration number. The code above checks the answer to Q1 and when the current loop reaches that number, the loop will break.

You can now run the survey and see how it works.

Example 2: Looping for X number of times according to a multi select question

Let’s suppose we need to ask a certain set of questions for each brand that the respondent has recognized. In this case we will first ask which brands the respondent recognizes, and then loop the “per-brand” questions only through the brands that were specified.

To perform this example we will do the following:

  1. Add the multi select “Which brands do you recognize” question + add the chapter with the “per-brand” questions.
  2. Configure an answer scale for easier looping configuration.
  3. Configure the looping.
  4. Show the brand name in the first question.


Step 1: Add the numeric questions

c14-7

Step 2: Configure an answer scale for easier looping configuration

To quickly create a scale out of a question answers, you can right click on the question and select the “Make into scale” option:

c14-8

You will now be able to reuse this scale throughout the survey and also in the Loops tab as you will see below. Please refer to Chapter 12 for more information about scales.

Step 3: Configure the looping

We will use the newly created scale when configuring the looping parameters:

c14-9

This instructs the survey to loop through the available brands in the list of brands we have configured. We will now add an entrance rule to make sure the survey skips the brands which were NOT selected in Q1. First, select the “Use entrance rule” option:

c14-10

Then add the following entrance rule. Make sure you are adding the code to the Iteration Entrance Rule section:

c14-11

Since the chapter loops through the scale that is also used with Q1, this rule checks if the user has selected in Q1 the current iteration item.

You can now run the survey and see how it works.


Step 4: Show the brand name in the first question

You can make use of the newly introduced “IterationName” value to show the name of the brand anywhere you need to. Let’s configure the first question of the loop chapter to show the current brand name for which we will ask questions.

Below is the text of the empty question that will hold the brand name. Notice the {0} at the end that is used for text substitution:

c14-12

Now, let’s add a start script to this question that will replace the {0} with the current brand name:

c14-13

Notice the use of the “IterationName” value to specify the current iteration name. Please note that since we are iterating through a predefined scale, the IterationName equals the name of the answer from the scale which in our case is the brand name.

Go To  Chapter 15 – Loading Excel Lists As Question Answers

Back to Table Of Contents

Visit us at:  http://www.dooblo.net

  1. September 19, 2012 at 7:32 am

    It seems that SurveyToGo do not support Loop inside Loop construction, right?

  1. December 14, 2009 at 10:03 am
  2. December 14, 2009 at 12:52 pm
  3. April 23, 2012 at 10:14 am

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: