> For the complete documentation index, see [llms.txt](https://docs.avoautomation.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avoautomation.com/avo-assure/support-resources/knowledge-base-articles/design-studio/test-case/using-if-and-else-conditions-inside-a-for-loop.md).

# Using If and Else Conditions Inside a For Loop

**Summary:** This article explains how to use If and Else conditions inside a For loop in Avo Assure. It also provides an example of displaying the current iteration number when it is greater than 3 and displaying a different message for the remaining iterations.

### Error Behavior

Incorrectly configured If and Else blocks inside a For loop can cause the Test Case to fail or execute the wrong steps. This may result in unexpected output values or prevent the loop from completing as expected.

### Possible Reasons

This issue may occur due to one or more of the following reasons:

* The If condition uses an incorrect variable, comparison operator, or value.
* The `{Count}` output variable is not configured to store the current iteration number.
* The **Else** action is placed outside its corresponding If block.
* The If block is not closed with **EndIf** before **End-For**.
* The **End-For** action is missing, leaving the loop structure incomplete.

### Resolution/Solution

To use conditions inside a For loop, configure the loop and add the required conditional actions.

1. Add a **For** action and specify `5` as the number of iterations. Store the current iteration number in the `{Count}` output variable.
2. Add an **If** action inside the For loop with the condition `({Count};>;3)`.
3. Add a **Display Variable Value** action under If and provide `{Count}` as the input value.
4. Add an **Else** action and then add another **Display Variable Value** action with `Below 3` as the input value.
5. Add **EndIf** to close the conditional block.
6. Add **End-For** to close the loop.

#### Example: Using If and Else Conditions Inside a For Loop

In this example, we explain how to display the current iteration number when it is greater than 3. For the remaining iterations, the action displays **Below 3**.

Configure the following Test steps:

<table><thead><tr><th width="69.3333740234375">Steps</th><th>Elements</th><th width="196.333251953125">Actions</th><th width="118.8333740234375">Input Value</th><th>Output Value</th></tr></thead><tbody><tr><td>1</td><td>@Generic</td><td>For</td><td>5</td><td><code>{Count}</code></td></tr><tr><td>2</td><td>@Generic</td><td>If</td><td><code>({Count};>;3)</code></td><td>N/A</td></tr><tr><td>3</td><td>@Generic</td><td>Display Variable Value</td><td><code>{Count}</code></td><td>N/A</td></tr><tr><td>4</td><td>@Generic</td><td>Else</td><td>N/A</td><td>N/A</td></tr><tr><td>5</td><td>@Generic</td><td>Display Variable Value</td><td>Below 3</td><td>N/A</td></tr><tr><td>6</td><td>@Generic</td><td>EndIf</td><td>N/A</td><td>N/A</td></tr><tr><td>7</td><td>@Generic</td><td>End-For</td><td>N/A</td><td>N/A</td></tr></tbody></table>

### Logical Explanation

The For action repeats the steps five times and stores the current iteration number in the `{Count}` output variable. During each iteration, the If action checks whether the value stored in `{Count}` is greater than 3.

* If the condition is **True**, the Display Variable Value action displays the value stored in `{Count}`.
* If the condition is **False**, the steps under Else run, and the Display Variable Value action displays **Below 3**.

The EndIf action closes the conditional block. End-For moves execution to the next iteration until the loop completes all five iterations.

### Additional Notes

* Close every If block with **EndIf** before **End-For**.
* Use **Else-If** when you need to check additional conditions.
* **Start Loop** and **End Loop** differ from For. They repeat steps for each data row loaded using **Get Param** and do not require a specified iteration count.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.avoautomation.com/avo-assure/support-resources/knowledge-base-articles/design-studio/test-case/using-if-and-else-conditions-inside-a-for-loop.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
