# Loop Operations

##

{% hint style="info" %}
Looping functionality will work on the datasets which were created by loading files into RDA and/or via logical dataset creation from other datasets.
{% endhint %}

## 1. Timed loop&#x20;

Step 1: Create an empty **timed\_loop\_example\_1** using AIOps studio as shown in the below screenshot

![Empty pipeline ](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MgCc_Z-hUCPz_aCOdw9%2F-MgCdHqQVASyX86DiOAc%2FScreen%20Shot%202021-08-03%20at%201.12.07%20PM.png?alt=media\&token=1bb82039-a8a7-4412-8eaa-764a02a84fb0)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.

\
*`###### Pipeline for timed loop: Sleeps 'interval' seconds after each iteration.`*\
*`###### if the max_iterations is specified, loop will stop after max_iterations reached`*\
*`###### each iteration as variable loop_index set (starts at 0 and increments by 1)`*\
\
*`@c:timed-loop interval = '3' & max_iterations = 10`*\
&#x20;   *`--> @dm:empty`*\
&#x20;   *`--> @dm:addrow message = "This is row number ${loop_index}"`*\
&#x20;   *`--> @dm:save name = "temp-df-${loop_index}"`*\
\
*`--> @c:new-block`*\
&#x20;   *`--> @dm:concat names = "temp-df-.*"`*<br>

![Pipeline code added for timed loop example](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MgCerI4zR1uq7NZiO2j%2F-MgCfYvRaVGStapYvqm1%2FScreen%20Shot%202021-08-03%20at%201.21.57%20PM.png?alt=media\&token=e6a63572-fdce-4236-82ab-c004f2b88e2f)

Step &#x33;**:** Click verify button to verify the pipeline. RDA will verify the pipeline without any errors (as shown below)

![Loop pipeline code is verified for syntax errors as shown in above screenshot](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MgCfsEUQBl1N7WbBFdr%2F-MgCgJgtdXOSHA6WwBzk%2FScreen%20Shot%202021-08-03%20at%201.25.22%20PM.png?alt=media\&token=7b0ee371-1941-48c0-bd1c-379d3dee42d9)

Step &#x34;**:** Click execute button to execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

![Screenshot-1 ](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MgCh6d-L88YvqCF0jtX%2F-MgCh9WG8lTpVqbcU2Ym%2FScreen%20Shot%202021-08-03%20at%201.28.53%20PM.png?alt=media\&token=25b427eb-d7f2-4347-92af-fb6eb75c32bc)

RDA executes a looping-based pipeline and prints the loop details as shown in the above screenshot. During each iteration/loop, the pipeline screen updates the iteration number as shown in the above screenshot.

![Screenshot-2](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MgChMKS2ObDYYH0dTzm%2F-MgChdIXlJ3N_KShH2Ev%2FScreen%20Shot%202021-08-03%20at%201.31.11%20PM.png?alt=media\&token=6e115a4a-9da7-4a35-8f51-599fabf113b4)

After iterating through max\_iterations, pipeline data is stored in output and exits.

Step 5: Verify the data after the timed loop operation is completed as shown in the below screenshot (data is printed for 10 iterations in this example).

![Output is printed after max\_iterations as shown in the above screenshot.](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MgCjGq_U19m8yIcXrog%2F-MgCjIXf3OGZOYe3nMDn%2FScreen%20Shot%202021-08-03%20at%201.38.19%20PM.png?alt=media\&token=98c1cb90-e5d7-4d0e-b962-6f5724fe7547)

## 2. Count loop

&#x20;Step 1: Create an empty **count\_loop\_example\_1** using AIOps studio as shown in the below screenshot.

![Empty pipeline](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MgIIPVLcAk4gmR7i4Gt%2F-MgIJELmxShP-jidq8en%2FScreen%20Shot%202021-08-04%20at%203.37.18%20PM.png?alt=media\&token=8fb07103-2439-41ae-b924-f6cff32550c8)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.

\
*`###### Pipeline for count loop: starts with 'start' number and increment by using`*\
*`###### 'increment' until the value is greater then equal to 'end' variable`*\
*`###### value for the each iteration is set as 'loop_index'`* \
\
*`@c:count-loop start = 0 & end = 10 & increment = 1`*\
&#x20;   *`--> @dm:empty`*\
&#x20;   *`--> @dm:addrow message = "This is row number ${loop_index}"`*\
&#x20;   *`--> @dm:save name = "temp-df-${loop_index}"`*\
&#x20;   *`--> @c:new-block`*\
&#x20;   *`--> @dm:concat names = "temp-df-.*"`*<br>

![Pipeline code is added to loop count pipeline example](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MgIK5VGdcSvdE2NE0Fe%2F-MgIKTQCAxIC13bGV_ke%2FScreen%20Shot%202021-08-04%20at%203.43.13%20PM.png?alt=media\&token=b5b0960d-2b77-4d59-be71-e51bffc8e5af)

Step &#x33;**:** Click verify button to verify the pipeline. RDA will verify the pipeline without any errors (as shown below)

![Loop pipeline code is verified for syntax errors as shown in above screenshot](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MgIKgLS66cAlFzK4x0I%2F-MgIL0ETpCKFDegG5jEi%2FScreen%20Shot%202021-08-04%20at%203.45.38%20PM.png?alt=media\&token=4d3dcebf-e9ad-47e1-9703-5fadf840b92d)

Step &#x34;**:** Click execute button to execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

![Screenshot-1](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MgIL97G2D9I4M_ReF1w%2F-MgILczH8wN_eztiZIf2%2FScreen%20Shot%202021-08-04%20at%203.48.19%20PM.png?alt=media\&token=d1b13726-0a4a-402c-90b2-203aa5c406df)

RDA executes a loop-count-based pipeline and prints the loop details as shown in the above screenshot. During each iteration/loop, the pipeline screen updates the iteration number as shown in the above screenshot.

![](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MgILtnc4ClT5qHzXdW9%2F-MgIM71eqLV_hqEIo3BQ%2FScreen%20Shot%202021-08-04%20at%203.50.28%20PM.png?alt=media\&token=0a199b10-f1f4-466d-98c5-83cd3b8661ce)

After iterating till 'end', pipeline data is stored in output and exits.

![Output is printed after end of all iterations as shown in the above screenshot.](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MgIMH1vWJlPfgNdctAz%2F-MgIMhC-RojPqucAPX3-%2FScreen%20Shot%202021-08-04%20at%203.53.03%20PM.png?alt=media\&token=02014ff0-15c1-49bd-962f-91e6c6c53f30)
