app builder

Repeating questions

Updated: June 7, 2021

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 image above, the loop collects info about the end-user's children, so the 'end of loop' question is "Do you want to add another child?"

This is what the 'end of loop' section looks like from the end-user's perspective:

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.

The End of Loop question looks like this:

The End of Loop allows the end-user to add another loop member (clicking "+ Add"), edit / delete existing loop members, or click "continue" to progress with the app.

If the end-user clicks "back" from the End of Loop question, they're presented with a warning:

The reason for this warning is that going back undoes the loop, i.e. all loop members will be destroyed. If the end-user wants to edit / delete individual loop members, they should click "edit" or "delete" for that loop member on 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.

Frequently Asked Questions

Don't see your question? Get support.

On this page