# loop

## Description

Loop through a range of values or a list of elements

## Input / Parameter

| Name  | Description                                                | Input Type | Default | Options | Required                                  |
| ----- | ---------------------------------------------------------- | ---------- | ------- | ------- | ----------------------------------------- |
| start | The starting point of the range of values to loop through. | Number     | -       | -       | required if “data” has no input           |
| end   | The ending point of the range of values to loop through.   | Number     | -       | -       | required if “data” has no input           |
| data  | The list of elements to map.                               | List       | -       | -       | required if “start” OR “end” has no input |
| extra | Additional data to be used in the callbacks.               | Any        | -       | -       | No                                        |

## Output

| Description                        | Output Type |
| ---------------------------------- | ----------- |
| Returns the formatted information. | Object      |

### Object

| Key     | Description                                                             | Output Type |
| ------- | ----------------------------------------------------------------------- | ----------- |
| success | Boolean value to denote whether the function was executed successfully. | Text        |
| message | The message to print.                                                   | Text        |
| data    | Any additional message or data to print.                                | Text        |

## Callback

### callback

The function to be executed when the loop runs successfully.

## Example

In this example, we will loop through a range of numbers and print the values as they are looped through in the console.

### Steps

1. Drag a button component to a page in the mobile designer and open up the `Action` tab.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-84a8896784ad4aa97784708d9f9acfdd14861968%2Floop-step-1.png?alt=media)
2. Select the event `click` and drag the `Control.loop` function to the event flow.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-938c68f3e0b1b234233daea7a5e3d3a44a9230df%2Floop-step-2.png?alt=media)
3. Fill in the parameters of the function.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-2dbeab743b8c3473d7f62f3a94df19cd3a4dc2e8%2Floop-step-3.png?alt=media)
4. Drag the function to be executed if the loop function is successful to the node below the function. In this example, we are using the `Log.write` function and change the parameters dropdown to use `input`

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-aa2aa7b62a5a050d3964543bf525ab4cdd1917b4%2Floop-step-4.png?alt=media)

### Result

1. The range of values will be printed in the console.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-b59d8c18cf561268adc7ed02190eed36d50fa362%2Floop-result-1.png?alt=media)
