Having issues with a nested foreach loop. I want to iterate through a list of answers and write that to specific bookmark locations in a word document. I can write to the correct locations but the loop just continues forever. I tried inserting an if statement to exit the loop if the index is at the end but it still loops forever.
Attached is an image of my loop with a nested foreach loop. I tried two foreach loops and still not working.
How long is your Answers list/datatable? That might make it go on too long since for every LoopIndex it will loop through all the answer. So for every bookmark it will insert all the answers.
I think the problem is that your for each loop will always overwrite the bookmark Q%LoopIndex%. So every bookmark will have the last item in %Answers% list.
Do you want to insert one answer per bookmark? If so I would just remove the outer Loop and add BookmarkIndex variable that you increase every for each loop. Then have condition that if %BookmarkIndex% is greater than 24 exit the loop.
Like so:
Was this reply helpful?YesNo
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.