app builder

Repeating questions

Updated: October 17, 2020

Your app can ask the end-user the same question multiple times. This is the best way to collect information about an undefined number of people/items/things.

The classic use-case for repeating questions is collecting information about the end-user's children.

To repeat questions, use a Loop Section. This allows you to create a group of Blocks that are repeated over and over as long as the end-user answers "yes" to the End of Loop question:

You customize the End of Loop question to fit the context. In the above example, the loop is collecting information about the end-user's children.

How loops work

Your Loop Section must include at least one Page Block inside of it. The end-user will loop (i.e. repeat) over the block(s) inside your Loop Section until they answer "no" to the End of Loop question.

How to use data collected in a loop

This Loop Section defines two variables, child_name and child_ssn:

Variables that are defined within a Loop Section can't be used outside the Loop Section, unless you use a List Block.

Loop Sections are a closed environment where nothing can come out unless you specify exactly how it should come out (which is what List Blocks are for). This makes sense if you think about the consequence of the end-user repeating over the above loop six times: in this scenario, what does it mean to use the variable child_name? If you add child_name to a document, do you want to list the names of all six children? Or do you want to list only the first child's name? You can provide these instructions with List Blocks.

An intro to lists

A list is a type of data structure. A list has "members":

Loop Sections create lists. Every time the end-user repeats over your loop, they create a new list member.

A Loop Section is not the only way to create a list in Afterpattern. A Query Block, which pulls rows of data out of your database and into your app, also creates a list.

In order to use list member data, you must instruct your app on how exactly you want to structure that data. This is what List Blocks are for.

Contact us for support

Talk to a real person, quickly. We're available 9am - 5pm EST.