# Loop

iframe
Repeats a set of nodes a specified number of times or iterates over each item in an array. Use this to process lists, retry operations, or perform repetitive tasks.

## Parameters

- **Loop Type**
  - **Number Loop**: Repeat the enclosed nodes a fixed number of times.
    - **Loop Count**: The number of iterations. Enter a number or reference a variable.
  - **Array Loop**: Iterate over each element in an array.
    - **Array**: Reference an array variable (e.g., the element list output from [Find Element](/rparobotic-process-automation/03-node/01-simulation-operations/03-find-element)).


## Output

- **Output Parameters**
  - **Current Index**: The current iteration index (0-based)
  - **Current Item** (Array Loop only): The current element in the array
- **Execution Log**
  - Start Time
  - End Time
  - Duration (ms)
  - Status (Success/Failure)


## Example

### 1. Number Loop — Swipe through 5 pages

Swipe the screen 5 times to browse through content:

| Field Name | Field Value |
|  --- | --- |
| **Loop Type** | Number Loop |
| **Loop Count** | 5 |


Inside the loop, add a [Swipe Page](/rparobotic-process-automation/03-node/01-simulation-operations/07-swipe-page) node followed by a [Wait](/rparobotic-process-automation/03-node/03-flow-logic/01-wait) node (e.g., 2000ms) to pause between swipes.

### 2. Array Loop — Process a list of found elements

Use [Find Element](/rparobotic-process-automation/03-node/01-simulation-operations/03-find-element) with "Get element list" to get all matching elements, then loop through each one to extract its text:

**Step 1: Find all app icons**

| Field Name | Field Value |
|  --- | --- |
| **When Condition is Met** | `fullId` Equals `com.android.launcher3:id/icon` |
| **When there are multiple matching objects on the page** | Get element list |


**Step 2: Loop through the element list**

| Field Name | Field Value |
|  --- | --- |
| **Loop Type** | Array Loop |
| **Array** | `{{Find Element.Element list}}` |


**Step 3: Inside the loop — Tap, Wait, and Return**

| Field Name | Field Value |
|  --- | --- |
| **Tap Element** | **Use Previous Element{{Loop.Current Item}}** |
| **Wait** | **3000ms (Wait for the app to load)** |
| **Press Key** | **Back** |


![loop](/assets/loop.9c806031b5335087c5aeb5d0cb20a1d68002e0d3b24a36ce0dba93eefea20045.e6dfb5c5.png)

This will iterate through all the apps on your desktop and then exit them.

## Tips

- **Avoid infinite loops**: Always ensure your loop has a defined exit condition. Number Loop naturally stops; Array Loop stops when all items are processed.
- **Add delays between iterations**: Insert a [Wait](/rparobotic-process-automation/03-node/03-flow-logic/01-wait) node inside the loop to prevent actions from executing too rapidly.
- **Use Current Index for conditional logic**: Combine with [Switch](/rparobotic-process-automation/03-node/03-flow-logic/03-switch) to execute different actions on specific iterations (e.g., skip the first item, or stop after the 10th).
- **Nested loops**: You can place a Loop node inside another Loop node for multi-level iteration (e.g., loop through pages, then loop through elements on each page).


## Related Nodes

- [Find Element](/rparobotic-process-automation/03-node/01-simulation-operations/03-find-element) — often provides the array for Array Loop
- [Switch](/rparobotic-process-automation/03-node/03-flow-logic/03-switch) — add conditional branching inside loops
- [Wait](/rparobotic-process-automation/03-node/03-flow-logic/01-wait) — add delays between iterations
- [Run JS Script](/rparobotic-process-automation/03-node/02-data-processing/01-run-js-script) — process individual items inside the loop