Skip to content

Added Loop Over List Info #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
42 changes: 37 additions & 5 deletions docs/resources/control-flow/functions/loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,46 @@ sidebar_position: 5
keywords: [Loops, Backend Query, Backend Logic, Control Flow, FlutterFlow]
---

Sometimes, you might want to trigger certain actions multiple times. For example, an app might fetch data from a server, and you want to handle network errors by retrying the request up to a certain number of times.
# Loops

:::info
Every loop requires a condition, and the actions within the loop will continue to trigger as
long as the condition holds true. When the condition becomes false, the loop terminates, and the next actions in the workflow will trigger.
:::
**Loops** in FlutterFlow allow you to perform repetitive tasks without writing complex code. This is useful when working with lists of data or when you want to repeat actions a certain number of times.

There are two types of loops supported in FlutterFlow:

## While Condition Loops

A **While Condition** loop requires a condition. The actions within the loop will continue to trigger as long as the condition holds true. When the condition becomes false, the loop terminates, and the next actions in the workflow will trigger.

For example, you can use a While Condition loop to continuously check if a user is still within a geofenced area. As long as the condition `isUserInLocation == true` holds, the app might keep checking for updates or show a live indicator.

![loop-block.png](img/loop-block.png)

## Over List

This loop type lets you iterate over a list of items to perform actions for each item in the list.

For example, if you have a list of items in a shopping cart and want to calculate the total price or apply a discount to each item, you can use Over List to go through each product and perform a calculation for each one.

You can also customize how the loop iterates:

- **Start Index**: Where the loop starts (default is `0`).
- **End Index**: Where the loop ends (default is the length of the list).
- **Step Size**: Interval between each iteration (e.g., set to `2` to loop through every second item).
- **Reverse Order**: Enables the loop to iterate from the end of the list to the beginning (e.g., showing the latest messages first).

![loop-over-list.avif](img/loop-over-list.avif)

Inside a loop, you can access the current item and its index. This gives you the ability to work with each item individually, such as displaying item-specific data and making calculations.

![access-item-inside-loop.avif](img/access-item-inside-loop.avif)

:::tip[Nested Loops]

You can also add a loop inside another loop to handle related data structures. For example, looping through orders and then looping through each order’s line items.

:::


## Loop Breaks

:::danger[AVOID an INFINITE LOOP]
Expand Down