Automatically looping (repeating) through different choice list_names?

1. What is the problem? Be very detailed.
Hello, I have a consumption questionnaire with multiple consumption categories (food, household durables etc.), each with a select_multiple response and some follow-up questions.

Given that I have 12 consumption categories, I do not want to write out the code for each category separately (making changes would become a nightmare), but I want a way to loop over some kind of 'meta-list that contains the list_names associated with each consumption category so that on each iteration of the loop it calls the appropriate list_name moving sequentially through all 12 consumption categories.

Just wondering what the most efficient way to program something like this is?

2. What app or server are you using, and on what device and operating system? Include version numbers.
Windows KoboCollect

3. What you have you tried to fix the problem?

My first impulse was to write a calculate block that takes the repeat position and checks that against a series of if statements that create a variable containing the appropriate list_name for the given repeat position. However, I have noticed that the if statements in ODK always have an 'else' attached to it, and do not know how to get it to return "nothing". Thus ensuring that if statement calls further down the block do not override any populated value.

4. What steps can we take to reproduce the problem?

5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.

I have attached a rough example of what I am trying to achieve, you will see in the select_multiple the list is trying to be dynamically drawn from the reference variable "consume_list", but I am still too new at this to understand the proper way of going about this.

test_repeat.xlsx (14.9 KB)

Welcome to the ODK forum, @jeff_Andrews! We're glad you're here. When you get a chance, please introduce yourself on this forum thread. I'd also encourage you to add a picture as your avatar because it helps build community!

The attached example form shows how to loop through a group of questions once for every selected answer from a previous select_multiple. Right now there is only 1 question in the group but you could easily add more. Could this format be applied to your situation?

repeat_loop.xlsx (10.7 KB)

|          type           |       name        |                              label                              | required |                                  calculation                                  |              count              |
| select_multiple sectors | intervention      | What are the sectors of intervention?                           | yes      |                                                                               |                                 |
| begin_repeat            | sectors           | Sectors of intervention                                         |          |                                                                               | count-selected(${intervention}) |
| calculate               | this_sector_name  |                                                                 |          | selected-at(${intervention},position(..)-1)                                   |                                 |
| calculate               | this_sector_label |                                                                 |          | jr:choice-name(selected-at(${intervention},position(..)-1),'${intervention}') |                                 |
| text                    | sub_sector        | What is the ${this_sector_label} sub-sector(s) of intervention? |          |                                                                               |                                 |
| end_repeat              |                   |                                                                 |          |                                                                               |                                 |