Skip to content

Commit d9bc3ee

Browse files
committed
Added Loop Over List Info
1 parent aedafab commit d9bc3ee

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed
Binary file not shown.
Binary file not shown.

docs/resources/control-flow/functions/loops.md

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,46 @@ sidebar_position: 5
77
keywords: [Loops, Backend Query, Backend Logic, Control Flow, FlutterFlow]
88
---
99

10-
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.
10+
# Loops
1111

12-
:::info
13-
Every loop requires a condition, and the actions within the loop will continue to trigger as
14-
long as the condition holds true. When the condition becomes false, the loop terminates, and the next actions in the workflow will trigger.
15-
:::
12+
**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.
13+
14+
There are two main types of loops supported in FlutterFlow:
15+
16+
## While Condition
17+
18+
**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.
19+
20+
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.
1621

1722
![loop-block.png](img/loop-block.png)
23+
24+
## Over List
25+
26+
This loop type lets you iterate over a list of items to perform actions for each item in the list.
27+
28+
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.
29+
30+
You can also customize how the loop iterates:
31+
32+
- **Start Index**: Where the loop starts (default is `0`).
33+
- **End Index**: Where the loop ends (default is the length of the list).
34+
- **Step Size**: Interval between each iteration (e.g., set to `2` to loop through every second item).
35+
- **Reverse Order**: Enables the loop to iterate from the end of the list to the beginning (e.g., showing the latest messages first).
36+
37+
![loop-over-list.avif](img/loop-over-list.avif)
38+
39+
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.
40+
41+
![access-item-inside-loop.avif](img/access-item-inside-loop.avif)
42+
43+
:::tip[Nested Loops]
44+
45+
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.
46+
47+
:::
48+
49+
1850
## Loop Breaks
1951

2052
:::danger[AVOID an INFINITE LOOP]

0 commit comments

Comments
 (0)