The way your code has been commented suggests this is AI-generated.Hi everyone,
I’m having trouble with a script where I need to loop through an array and display its contents. My goal is to create a list from the array values and set it in a field. However, the field is only displaying the first value of the array, not iterating through the rest.When I run the script, only "Apple" is displayed in the field "fruitList". The other values are not being added to the field.CODE:
-- Define and populate the arrayput "Apple" into tArray["fruit1"]put "Banana" into tArray["fruit2"]put "Cherry" into tArray["fruit3"]-- Initialize the fieldput "" into fld "fruitList"-- Loop through the array and display valuesrepeat for each key tKey in tArray put tArray[tKey] & cr after fld "fruitList"end repeat
Is there something wrong with the way I’m using the `repeat for each` loop to iterate through the array?
How can I ensure all values in the array are displayed in the field?
Nevertheless, the code is correct and works as expected: All 3 values are displayed, so can't explain your issue - look at the rest of your code if you are genuinely having this problem.
For such a simple array structure, instead of looping consider using combine instead:
CODE:
combine tArray using return
Statistics: Posted by stam — Wed Aug 21, 2024 8:07 am