'For' loops are a very common function\feature which is one of the basic fundamentals of programming.
It used in most of the known programming languages and it is very useful for many different scenarios.
This 'How-To' will introduce you to 'For' loops and will explain how to use them in SurveyToGo.
Step 1: Introduction & Structure of 'For' loops.
Step 2: Implementing 'For' loops in SurveyToGo.
[Initial Expression] : This piece of code runs only once , at the moment the loop is entered.
[condition] : This piece of code is the condition which is checked each iteration before it begins.
[Increment Expression] : This piece of code is executed each time an iteration is ended.
2nd Param: The condition of the loop, as long as 'i' value is less than 10, the loop will run.
3rd Param: Here we would usually want to increment by 1 our initialization variable every end of iteration, so the loop will meet it condition sometime and end, if the condition would not be met, the loop will keep on going forever and ever and ever…etc'.
* '++' operator increments the variable from its left by 1.
Action Code (Withing the Curly Bracelets): Here you can write any code you have in mind, your only limit is your own imagination (and syntax limitations J).
For loops can be implemented wherever you want\need to use them, except for entrance rules and jump rules.
You can implement them in Start\End scripts, Survey Init code, Advanced scripts, etc'.
I would show you a nice use of 'For' loops in SurveyToGo.
Let's say, for example, that we want the next single choice question to show only workers which are rated less than average.
In that case we can use a 'For' loop that will iterate according the topics and will filter out only the ones suitable to our request, for example.
basically what I did here is configured a loop to run from 1 until the number of topics in the previous question, incrementing 'i' each iteration by 1.
Each iteration I checked if the answer of Topic i, in the previous question, is less or equal to 3.
If the answer is less or equal to 3, what means Average, good or Excellent, so I would like to hide that answer, by using SetAnswerVisible, with the value of 'i'.
* The single choice question will have the same names in the same order as answers.
There is no limit to what you can do with 'For' loops, this is just a basic example of how you can use it for basic things in SurveyToGo.