# For Loop Alternative for Populating Dropdown Options?

I’m sure I’m missing something simple, and I apologize in advance for the potentially ‘basic’ question, but I’ve searched for quite a few days, and can’t figure out how to accomplish this…

I have a data variable (max_score) in the datasource.
I want to have a dropdown that shows you selectable options from 0 up to the max_score variable value.
For example if the max_score is 5, I want the dropdown list to display:
0
1
2
3
4
5

This seems to me like a simple for loop in most programming languages,
ie:

``````for (i = 0; i < max_score; ++i)
{
printf("%d ", i);
}

Is this possible, and how might I accomplish this?
(FYI - I've tried using a formula, but I'm not seeing a loop alternative there??)

Thanks all!!!``````

SEQUENCE(0, max_score, 1)

I’m learning too and am struggling without loops but it will be something like this if it’s not this. Check out the sequence formula…

nesting functions within functions for more complex ideas with MAPS, LOOKUP and the like are essentially ways of looping through data if that’s helpful down the track

Or You can simoly use the `GENERATE_RANGE()` formula.

For looping in a formula You should use MAP() formula.

Cheers

Guys! Sincerely…thanks for the help…and I apologize for being a noob on this…
However, I think I ‘may’ be doing something more ‘fundamentally’ wrong.

I’m trying to generate the list of options to populate a “Dropdown” UI element, so that a user can select the number (in this case the “score” for a game, from 0 through the number defined in max_points).

However, when building the formula using some of the suggestions above (GENERATE_RANGE, and SEQUENCE), I’m seeing a ‘validation’ error: “List Items Are Incompaiable”

Seemingly I’m not able to use a ‘list’…or for some reason this specific list to populate the dropdown?
I’ve tried casting the list elements to “NUMBER”, but still no luck.

I’m pretty sure I need to use a MAP here in some way…but I’m getting stuck on how to iterate through the range in a MAP…??

Any other thoughts??
Thanks!

+++++++++++++++++++++++++++++++++++++++++++++++

UPDATE:

I think I have this almost right:

MAP(GENERATE_RANGE(0, NUMBER(data.games1.max_points),1), {label: item, value: item})

HOWEVER…I’m still seeing the ‘validation’ error: “List Items Are Incompatible”…and I’m not seeing the “0” option in my Dropdown list.

Thoughts??
Thanks!

The problem here is that the dripdown component options list takes in a “list of objects” with two properties. One property is “value” and the other one is “label”.
So the MAP() would be as follows:

``````MAP(GENERATE_RANGE(0, appVars.maxPoint), {label: item, value: item})
``````

“Item” refers to the current item in the Map function. This is why You can use that to populate the list if objects.
Now please correct my above formula accordingly to Your data variables and range steps.

This is great!

UPDATE:

I think I have this almost right:

MAP(GENERATE_RANGE(0, NUMBER(data.games1.max_points),1), {label: item, value: item})

HOWEVER…I’m still seeing the ‘validation’ error: “List Items Are Incompatible”…and I’m not seeing the “0” option in my Dropdown list.

Thoughts??
Thanks!

I am not sure why You don’t see 0, but the warning can be left there. That is there because the “item” is of type number and the strict declaration of the “options” list of objects has “text”. So that is something You should keep in mind when saving the output. You will have to use the NUMBER() formula again.