# While...Loop

Walk--through of <a href="/features/logical-steps/while-loop#Build-a-While-loop">Do...While Statement process</a> and <a href="/features/logical-steps/while-loop#Execution-Status">execution status overview</a>.

## Build a While loop

1. Create a Web Test and click Record.

2. Navigate to [www.random.org](http://www.random.org/).

3. Set the Min field to 1 and the Max field to 10.

4. Click Generate.

   ![Random](https://www.telerik.com/teststudio/documentation/assets/6d440076c98f175db67bca50c4a12776/rnd-gen-page.png)

5. Enable hover over highlighting and hover over the *Result* box.

6. Click **Build Step**.

   ![Build Verification](https://www.telerik.com/teststudio/documentation/assets/b0eeb6288111ba4584682b102d17c696/rnd-gen-element-drop-down.png)

7. Choose **Content** under **Verifications** in the <a href="/getting-started/test-recording/step-suggestions" target="_blank">**Step Builder**</a>.

* Set the first drop-down to **InnerText**.
* Set the second drop-down to **NotContain**.
* Click **Add Step**.

![Content](https://www.telerik.com/teststudio/documentation/assets/3b7b113f6f171799c85c72b0d8f9912a/advanced-rec-tool.png)

8. Disable hover over highlighting and minimize the browser.

9. Choose **Conditions** in the <a href="/getting-started/test-recording/step-suggestions" target="_blank">**Step Builder**</a> and add **while...loop** step.

<table id="no-table" style="border:none;">
<tr style="text-align: center; background-color: transparent; border:none;">
<td>

<img src="/teststudio/documentation/assets/c02e56011a64cc759312ed7fed4610c0/step-builder-while-loop.png" alt="Standalone" /><br>**Standalone version**</td>

<td>

<img src="/teststudio/documentation/assets/af90b24c3aba6ff30c609e09065a5c02/vs-step-builder-while-loop.png" alt="VS Plugin" /><br>**VS Plugin**</td>

<tr>
</table>

10. Choose the verification we've already added from the dropdown of the While step.

![Choose Verification](https://www.telerik.com/teststudio/documentation/assets/8da8c6533861fd05cd86bcabf414729f/extended-menu-while-loop.png)

11. Uncheck/Delete the verification step so it will not be executed (We have this verification already added in the while step)

![Uncheck Verification](https://www.telerik.com/teststudio/documentation/assets/142726b1ae07f285de7518c84a0952ee/checkbox-unchecked.png)

12. Drag the Click Generate Button step into the WHILE step.

![Drag into While Step](https://www.telerik.com/teststudio/documentation/assets/be00aeb7feea38a15f1fce2709a5f752/drag-drop-step-in-loop.png)

13. Add an <a href="/features/custom-steps/execution-delay" target="_blank">Execution Delay</a> step from the More drop-down in the Add ribbon. Set it to 20 milliseconds.

14. Drag the *Execution Delay* step into the *WHILE* step.

![Drag Execution Step](https://www.telerik.com/teststudio/documentation/assets/4125a7b0ce97089059f03fa700e65095/fig10.png)

## Execution Status

15. Click Save and Execute. The test will continue to generate a random number between 1 and 10 until it generates the number referenced in the Verify step (4 in this example).

The **While step** will be always marked as 'Passed' since it is always executed - the condition is to be evaluated. Depending on whether the condition evaluation is true or false the test will either execute the \*\*while branch \*\* steps or skip and show them as 'Not Run'.

An execution status example when the while loop is executed few times and the steps in the while loop are executed at least once.

![While condition is evaluated at least once as true](https://www.telerik.com/teststudio/documentation/assets/d052392e777c85059a3565fb0f3f0bae/fig13.jpg)

An execution status example when the while condition is false and the steps in the while loop are not run at all.

![While condition is evaluated at least once as false](https://www.telerik.com/teststudio/documentation/assets/5f8b982a2b42dfe5b76cfe0b2904f81c/fig14.jpg)
