Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Help with Logic for Looping Questions

  • inovadados
  • inovadados's Avatar Topic Author
  • Away
  • New Member
  • New Member
More
1 day 10 hours ago #271424 by inovadados
Help with Logic for Looping Questions was created by inovadados
LimeSurvey version: LimeSurvey Cloud   Versão 6.15.5
LimeSurvey Cloud:Hello, good morning.My name is [Your Name], and I am new here. I need assistance with an issue. I have a multiple-choice question (Q1) where respondents can select up to 3 options. In the following block, I have three additional questions (Q2, Q3, and Q4) that need to be applied to each of the options selected in Q1.I would like to know if it is possible to create a loop that applies Q2, Q3, and Q4 to each option mentioned in Q1. If possible, could you guide me on how to implement this logic or share an example of how to set it up?Thank you in advance for your help!

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
23 hours 33 minutes ago #271425 by Joffm
Replied by Joffm on topic Help with Logic for Looping Questions
Hi, [Your Name] 

first, is there a special reason that some of the subquestions of "CORTE" are empty?
And you said "up to 3 options", but set "Maximum answers" to 1.

Well, to answer your question:
LimeSurvey does not support loops.
The straightforward solution is to create group "G2" as many times as there are subquestions in "CORTE".
Then you display the respective groups with "condition (object was selected in CORTE)" like
G2_1: CORTE_1=="Y"
G2_2: CORTE_2=="Y"
...
G2_36: CORTE_36=="Y"

A more sophisticated and shorter way is to display only three groups and taylor the object.
Therefore you create a group with hidden equations
Like
the base list: 
eqList0: {join(list(that.CORTE.shown),',')}
capture the first name:
eqN1: {trim(substr(eqList0,0,strpos(eqList0,',')))} 
the new list
eqList1: {str_replace(join(eqN1,','),'',eqList0)}
capture the second name (this is the first part of the new list):
eqN2: {trim(substr(eqList1,0,strpos(eqList1,',')))} 
capture the third name (this is the second part of the new list):
eqN3: {trim(substr(eqList1,strpos(eqList1,',')+1))}

As you already tried to show. you pipe the resp. name into the question text
Como você prefere comprar <b>{eqN1}</b>?

This way you only need three groups.
And the second and third grpoup get the condition "name is not empty"
!is_empty(eqN2)      !is_empty(eqN3)

Advantages/Disadvantages:
1. solution: straightforward, but you habe a lot of groups. Each group refers to one object
2. solution: only three groups needed, but you have to restructure the dataset. Each of the three groups can contain data of each object.

Joffm

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose