> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/hypersim/automation-api-and-scripting/automate-using-testview/test-commands-reference/general/loop.md).

# Loop

## Description

The Loop command is used to iterate in the test sequence. The number of times can be user-defined or auto-detected. If it is auto-detected, TestView is looking for the enabled multi-param option in the other commands to define the number of iterations necessary.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-fb9f47ec7e0ed77a4e34c3d9215816b25f441e15%2Fimage%20(1270).png?alt=media" alt=""><figcaption></figcaption></figure>

## Parameters

The ‘Operation’ option enables loop numbering. It is important to understand this option as it affects the way data is saved and thus the behavior of other commands. If left unchecked, each loop is considered as an independent test. If checked, each loop will have a different index. To understand the difference, look at the way the pdf documents are generated. The table below presents the difference for a test with one loop that iterates three times.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-1b08e936bbbfc8084629c884703094ed0429acb8%2Fimage%20(1271).png?alt=media" alt=""><figcaption></figcaption></figure>

On the left, the operation option is unchecked and hence, it creates three folders, one for each iteration. Conversely, when the operation is checked, the loops are numbered and thus only one folder is created for the test and the data for all iteration is saved in that folder.

This difference in architecture of the data makes a big difference in the way post-processing works as it only considers data in one folder. As an example, let’s suppose that we are looking for the maximum overcurrent value in post-processing. If 'Operation' is left unchecked, post-processing will only look at the last iteration (because it is the only one in the folder). Whereas if it is checked, it will compare all three iterations (because all three iterations are in the same folder).

The complexity increases when there is a loop in a loop. Below is an example of the pdf generated where the first loop has five iterations and the second three iterations.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-2a280e427d27d54973d7dea1061ba8bbe30187f9%2Fimage%20(1272).png?alt=media" alt=""><figcaption></figcaption></figure>

As it is possible to see, when the 'Operation' option of each loop is unchecked, each iteration is considered as independent (15 different folders). When both loops are checked or only the second one, it creates one folder per main loop.

When only the first loop is checked, the pdf creator overwrites the same file each time.

The second loop “Operation” has priority over the first one, i.e. when the test numbering of the second loop is different than 1, it will force the first loop to create a new folder. Therefore, if only the first loop is checked, it will force to have only one folder. However, as the second loop is not incrementing (not checked), it will not force the first loop to create a new folder and instead will rewrite the same file several times.

In brief, the ‘Operation’ checkbox in loops affects the way data is saved and therefore can impact other functions such as post-processing and tableOut as they depend on the way data is saved.


---

# 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://www.opal-rt.com/docs/hypersim/automation-api-and-scripting/automate-using-testview/test-commands-reference/general/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.
