‘for’, ‘while’, and ‘do-while’ statements

 The LoadRunner loop statement

To implement the logic of boilerplate code, a loop statement was added to the LoadRunner script. There are two ways in the LoadRunner script to send a specific request X times. To allow LoadRunner to send the request to the server, one method is to write the request X times. Another approach is to add the request to a script loop that has already been added. The loop resubmits the request for X iterations.

You need to understand logic to understand how a loop works. Initialization, conditions, and increments/decrements are the three components that make up a loop statement. A variable is initialized and assigned a value in the initialization part, and a comparison between the variable’s value and a condition determines whether to continue or break the loop. The last sentence changes the value of the variable by increasing or decreasing it. Let’s use an illustration to try to understand:

Example:

Consider a simple “for” loop statement with an integer loop variable, “i”. The loop should execute three times, followed by an exit. The statement of the ‘for’ loop is:

Int i;for (i=1;i<=3;i++) // Loop body{web_url(…) //Request}

i=1 => Give i its initial value of 1.

I <=3 => Determine the value of I before the start of the loop. It is necessary that the value of i is between 0 and 3.

i++ => After completing each loop, increase the value of i by 1.

What functions does a loop do?

  1. Loop 1: I start with a value of 1, which satisfies I =3 requirement. As a result, the loop body is executed and the request is received by the server. The value of i increases by one (i++) and becomes two (i=2).
  2. Loop 2: No initialization is done because, in the previous loop, I became 2 (i = 2). Evaluate the true state I =3 at this point. As a result, the server receives a second request. The value of i becomes 3 (i=3) thanks to the increment logic (i++).
  3. Loop 3: In the previous loop, the value of i is changed to 3 (i=3). Analyze if the real condition i=3 exists. The third time, the server receives the request. Now I have the value 4 (i=4).
  4. Loop 4: In the previous loop, the value of i is now equal to 4 (i=4). Analyze the condition I =3 that is not fulfilled. As a result, the control exits the loop without making the server request.

The aforementioned loop has accomplished its goal by sending the request to the server three times.

In LoadRunner, loop statements can be divided into three categories:

LoadRunner “for” loop
https://www.perfmatrix.com/wp-content/uploads/2020/01/LoadRunner_FlowLogic_for_Statement-2.png
LoadRunner “while” loop
LoadRunner while loop statement
LoadRunner “do while” loop
LoadRunner do while loop statement
Scroll to Top