Help with dynamic loop

1. What is the issue? Please be detailed.
I am trying to create the following loop: first comes to the intro, then the first phone number is asked for. If a phone number is entered then demographics are asked for. If no phone number is entered then it goes to the outro. After the first set of demographics, I want it to go to a different question asking for additional phone numbers which if one is entered will ask about demographics and if not then we go to the outro note.

2. What steps can we take to reproduce this issue?
I have included the XLS form that I am working with to show what I am trying to do.

3. What have you tried to fix the issue?
I have tried using the dynamic count function shown in the ODK docs, but have not been able to get it to work

4. Upload any forms or screenshots you can share publicly below.

ODK XLSForm template.xlsx (18.4 KB)

When using a repeat, it can complicate data analysis. You data export will have the primary data table, and then a secondary data table where each iteration of the repeat group will be a row of data. In your current design, you will have a primary data table with the first phone number. And then in your secondary data table, the first row will have the details of the first phone number and the second phone number. The second row will have the details of the second phone number and the third phone number. And so on. I think this might cause confusion or otherwise increase the chance of a mistake when analyzing the data.

I would move all your questions about each person inside the group and have only the questions for a single person within the repeat. You can then have language in your form to explain how to add another group. Are you going to be using Collect, Enketo, or both? The interaction for adding an additional group is slightly different, and you can adjust the language accordingly.

I've attached what I would suggest:
repeat group for messaging.xlsx (18.6 KB)

In Enketo...

In Collect...

Thank you so much for all your help! I was able to get the form to work really well (see attached). A quick question - on the question "would you like to add another phone number?" the loop restarts if you click yes. However, if you click yes, but go back and click no the loop does not stop but carries on. Is there any way to stop this?
CONSORT_InvitationtoMessage_2024_02_22.xlsx (16.6 KB)

Maybe, the documentation for controlling repeats can help you: